1

Phpmailer to send e-mail from any gmail

 3 years ago
source link: https://www.codesd.com/item/phpmailer-to-send-e-mail-from-any-gmail.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Phpmailer to send e-mail from any gmail

advertisements

I used the following code snippet using phpmailer class inorder to send an email using gmail server when a form is submitted in my web application! Though it works for my personel gmail address, it does not send emails when I replace my gmail address and password with my clients gmail address and password!

How can i correct this probem?

require "phpmailer/class.phpmailer.php"; //include phpmailer class

// Instantiate Class
$mail = new PHPMailer();  

// Set up SMTP
$mail->IsSMTP();                // Sets up a SMTP connection
$mail->SMTPAuth = true;         // Connection with the SMTP does require authorization
$mail->SMTPSecure = "ssl";      // Connect using a TLS connection
$mail->Host = "smtp.gmail.com";  //Gmail SMTP server address
$mail->Port = 465;  //Gmail SMTP port
$mail->Encoding = '7bit';

// Authentication
$mail->Username   = "[email protected]"; // Your full Gmail address
$mail->Password   = "******"; // Your Gmail password

// Compose
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "Pharmacy order confirmaton";      // Subject (which isn't required)
$mail->MsgHTML($message);

// Send To
$mail->AddAddress($_POST["Email"], "Recipient Name"); // Where to send it - Recipient
$result = $mail->Send();        // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);

When I send the message from my client's email, I get the error message:

SMTP Error: Could not authenticate.

How can I correct this issue?


Update your PHPMailer right now. You are running an old vulnerable version. Read the troubleshooting guide and do what it says. Do not use the submitter's address as the from address - its forgery and will make you fail SPF checks. Gmail does not let you send from arbitrary from addresses. Your auth problem is covered in the guide, but you will need to either enable less secure apps in Gmail, or implement oauth, as described in the docs and examples.

This has all been covered many times on SO - search before you post.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK