Hello to the entire forum,
I want to send emails with PHPMailer, these emails contain attachments.
My hosting account is free, what steps should I follow? Do I have to change any settings on the hosting?
Thank you and greetings
Hello to the entire forum,
I want to send emails with PHPMailer, these emails contain attachments.
My hosting account is free, what steps should I follow? Do I have to change any settings on the hosting?
Thank you and greetings
Hi! Welcome to the forum! You need SMTP server before using the PHPMailer library. You can use SMTP server from the Google Mail to send emails. You can follow the example from Admin:
Just setup PHPMailer like normal with your SMTP credentials, no special configuration necessary!
Well, it still doesnât work, I donât know if itâs bad hosting configuration, or zoho.
And I see that a lot of people have a lot of problems with PHPMailer.
Neither does theI also donât install it with Composer, which is what they recommend, but I donât know how it works.
Well, Iâll keep looking. Thank you!!!
If you want us to help find out why itâs not working, please describe the problems youâre having. Especially any error messages you get would be very helpful.
Where do you get that idea from? Sure, a lot of people who want to send email (and are having trouble with it) talk about PHPMailer. But thatâs not because PHPMailer is bad, itâs just because itâs basically the go-to option to send email with SMTP.
Composer is the de-facto way to manage third-party packages in your PHP project. Itâs useful to learn!
But if you donât feel like learning it, there is the php-download.com website that just delivers the package to you as an easy to use zip file: ⡠Download the PHP library phpmailer/phpmailer +++ One click!
If you can share the code your using (obviously removing credentials) Iâm happy to take a look for you. I had a nightmare getting PHPMailer working. Not because its bad, but because its quite a learning curve.
Once its working, its a really wonderful tool
Thank you very much admin, I will try it.
Greetings !!!
Hello dan3008.
Here I spend a code, the majority Iâve tried are like that.
I have followed the steps on the following website âŚ
https://php-forum.com/index.php?threads/php-mail-and-phpmailer.30517/
In the hosting, I have the structure of folders like this âŚ
And the code I use (testmail.php) is the following âŚ
I have commented on attachments, to have fewer problems, and neither send the mail.
And neither does the echo of the âerrorâ or âEmail Sent Successfully!â
I have not tried it with accounts of Zoho,Only with those of Gmail.
<?php
echo 'PHP_Mailer';
require 'PHPMailer-6.9.3/src/PHPMailer.php';
require 'PHPMailer-6.9.3/src/SMTP.php';
require 'PHPMailer-6.9.3/src/Exception.php';
//--------------------------------------------------
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = '********';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom([email protected]', 'Your Name');
$mail->addAddress([email protected]', 'Recipient Name');
$mail->isHTML(true);
$mail->Subject = 'Subject of the Email';
$mail->Body = 'Body of the Email';
//--------------------------------------------------
//$file_path = '/path/to/your/attachment.pdf'; // Path to the attachment
//$mail->addAttachment($file_path, 'filename.pdf'); // Adjust filename as needed
//$file_path = '/'; // Path to the attachment
//$mail->addAttachment($file_path, 'XDS2000.pdf'); // Adjust filename as needed
//--------------------------------------------------
if (!$mail->send()) {
echo 'Error: ' . $mail->ErrorInfo;
} else {
echo 'Email sent successfully!';
}
Thanks for everything !!!
Greetings !!!
are you using your gmail password or an app password?
I made that mistake. You need to generate and use an app password, not your normal login password
Hello @dan3008
I could already solve it, there were these failures.
1 - It had to activate the verification in 2 steps, in the sending account.
2 - Create a password app on the senderâs account, and use the 16 digit number in the password, Because with the normal password, to enter the account it does not work. (Give an SMTP connection error, which is the mistake that always gave me.)
3 - In the github code that passed the link, I had this âŚ
require 'PHPMailer-6.9.3/src/PHPMailer.php';
require 'PHPMailer-6.9.3/src/SMTP.php';
require 'PHPMailer-6.9.3/src/Exception.php';
And I saw that when opening the folder 'phpmailer-6.9.3 , Inside this folder there was another with the same name, And inside there were the php codes, so I put âŚ
require âPHPMailer-6.9.3/PHPMailer-6.9.3/src/PHPMailer.phpâ;
require âPHPMailer-6.9.3/PHPMailer-6.9.3/src/SMTP.phpâ;
require âPHPMailer-6.9.3/PHPMailer-6.9.3/src/Exception.phpâ;
Maybe all the codes that tested worked, but they were not going well, for not making the first 2 previous steps.
Well, finally solve it !!!He had more than 2 weeks, and there was no way to send an email.
Now I just have to try, attach files.
But I think before, I will take a coffee or a beer !!!
Thank you all. Greetings!!!
hahahahaha
Right now I was writing it to you !!!
Greetings !!!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.