

Phpmailer to send e-mail from any gmail
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.

Phpmailer to send e-mail from any gmail
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.
Recommend
-
113
PHPMailer – A full-featured email creation and transfer class for PHP Features Probably the world's most popular code for sending email from PHP! Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM...
-
77
Best rated mail merge for Gmail The best rated mail merge tool for Gmail. Save time on sending emails with Gmail. Email multiple recipient...
-
5
Brought to you by Mailmeteor, the best rated mail merge tool for Gmail. Gmail Mail Merge Script Example usi...
-
17
Send Email via SMTP Server in Laravel using PHPMailer Generally, we used the default mail() function to send emails in the PHP-based web application. But, the PHP mail() function sometimes fails to deliver...
-
4
Basic code example for email hosted at DreamHost Insert the following code into a PHP file.
-
7
PHPMailer — Installing on a VPS or Dedicated Server Overview PHPMailer allows you to send email from your site via SMTP. Visit
-
30
Configuring the 'WP Mail SMTP' plugin with Gmail Overview This article explains how to use the WP Mail SMTP plugin to send...
-
34
Sending Mail via Gmail using OAuth2 (2022 Edition) (Shallow Thoughts) Akkana's Musings on Open Source Computing and Technology, Science, and Nature.
-
9
How to Send Email in PHP using PHPMailer 466 views 7 months ago PHP Sending main in PHP application is very basic functionali...
-
5
使用 PHP 自带 mail https://www.php.net/manual/zh/function.mail.php public function testEmail() { $to = "[email protected]"; $subject = "...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK