本文介绍了PHPMailer - gmail smtp无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在我的网站中使用 gmail smtp 联系表单(PHPMailer脚本 https ://github.com/PHPMailer/PHPMailer )我的代码是:I use gmail smtp for contact form in my site.(PHPMailer script https://github.com/PHPMailer/PHPMailer)my code is:<?phpinclude "classes/class.phpmailer.php"; // include the class name$mail = new PHPMailer(); // create a new object$mail->IsSMTP(); // enable SMTP$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only$mail->SMTPAuth = true; // authentication enabled$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail$mail->Host = "smtp.gmail.com";$mail->Port = 465; // or 587$mail->IsHTML(true);$mail->Username = "[email protected]";$mail->Password = "xxxxxxxxxx";$mail->SetFrom("[email protected]");$mail->addReplyTo("[email protected]");$mail->Subject = "Your Gmail SMTP Mail";$mail->Body = "Hi, your first SMTP mail via gmail server has been received.";$mail->AddAddress("[email protected]"); if(!$mail->Send()){ echo "Mailer Error: " . $mail->ErrorInfo;}else{ echo "Message has been sent";}?>它有效,但我有两个问题:It works but i have two problems: 我设置 $ mail-> SetFrom([email protected]); 在我的gmail展示 from:[email protected]我设置 $ mail-> addReplyTo([email protected]); 但是在我点击重播按钮电子邮件时,我的gmail被重播到 main @ gmail .com 我的代码是I set $mail->addReplyTo("[email protected]"); but in my gmail when i click replay button email replayed to [email protected] code is推荐答案我找到了我的答案。您的Gmail中的转到I found my answer.in your Gmail go tosetting ->accounts ->Send mail as 点击添加您自己的其他电子邮件地址 在新窗口中输入新的电子邮件地址如果您的Gmail是 [email protected] ,您必须输入 [email protected] )或(如果您的gmail地址有点你必须改变点的位置示例如果你的Gmail是 [email protected] 你必须输入 yourma .il @ gmail.com ) 不要忘记取消选中视为别名。 点击下一步。 br>click Add another email address you ownin new window enter new email address (example if your gmail is [email protected] you must enter [email protected])or(if your gmail address have dot you must change position of dot.example if your gmail is [email protected] you must enter [email protected])don't forget uncheck Treat as an alias.click next step.返回到设置 - >帐户 - >发送邮件作为 创建一个新的电子邮件作为defult check 从同一个地址发送消息到 全部完成!我更改代码使用新的代码。 现在从我的网站显示go back to setting ->accounts ->Send mail asmake a new email as defultcheck Reply from the same address the message was sent toall done!i change code use new codes.now show from my site 现在当你点击重播botton显示重播到用户电子邮件now when you click replay botton show replay to user email<?phpinclude "classes/class.phpmailer.php"; // include the class name$mail = new PHPMailer(); // create a new object$mail->IsSMTP(); // enable SMTP$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only$mail->SMTPAuth = true; // authentication enabled$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail$mail->Host = "smtp.gmail.com";$mail->Port = 587; // or 587$mail->IsHTML(true);$mail->Username = "[email protected]";$mail->Password = "xxxxxxxxx";$mail->addReplyTo("[email protected]","user");$mail->SetFrom("[email protected]","My Site");$mail->Subject = "Your Gmail SMTP Mail";$mail->Body = "Hi, your first SMTP mail via gmail server has been received.";$mail->AddAddress("[email protected]"); if(!$mail->Send()){ echo "Mailer Error: " . $mail->ErrorInfo;}else{ echo "Message has been sent";}?> 这篇关于PHPMailer - gmail smtp无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-01 23:19