PHPMailer - gmail smtp无法正常工作 [英] PHPMailer - gmail smtp not working properly

查看:227
本文介绍了PHPMailer - gmail smtp无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站中使用 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:

<?php
include "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 = "main@gmail.com";
$mail->Password = "xxxxxxxxxx";
$mail->SetFrom("another@gmail.com");
$mail->addReplyTo("another@gmail.com");
$mail->Subject = "Your Gmail SMTP Mail";
$mail->Body = "Hi, your first SMTP mail via gmail server has been received.";
$mail->AddAddress("main@gmail.com");
 if(!$mail->Send()){
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
    echo "Message has been sent";
}
?>

它有效,但我有两个问题:

It works but i have two problems:


  1. 我设置 $ mail-> SetFrom(another@gmail.com);
    在我的gmail展示 from:main@gmail.com

我设置 $ mail-> addReplyTo(another@gmail.com);
但是在我点击重播按钮电子邮件时,我的gmail被重播到 main @ gmail .com

我的代码是

I set $mail->addReplyTo("another@gmail.com");
but in my gmail when i click replay button email replayed to main@gmail.com
my code is


推荐答案

我找到了我的答案。您的Gmail中的
转到

I found my answer. in your Gmail go to

setting ->accounts ->Send mail as

点击添加您自己的其他电子邮件地址
在新窗口中输入新的电子邮件地址如果您的Gmail是 yourmail@gmail.com ,您必须输入 your.mail@gmail.com )或(如果您的gmail地址有点你必须改变点的位置
示例如果你的Gmail是 yo.urmail@gmail.com 你必须输入 yourma .il @ gmail.com

不要忘记取消选中视为别名

点击下一步。 br>

click Add another email address you own in new window enter new email address (example if your gmail is yourmail@gmail.com you must enter your.mail@gmail.com)or(if your gmail address have dot you must change position of dot. example if your gmail is yo.urmail@gmail.com you must enter yourma.il@gmail.com)
don't forget uncheck Treat as an alias.
click next step.

返回到设置 - >帐户 - >发送邮件作为

创建一个新的电子邮件作为defult

check 从同一个地址发送消息到

全部完成!
我更改代码使用新的代码。

< img src =https://i.stack.imgur.com/Gda4X.pngalt =e n图像描述这里>

现在从我的网站显示

go back to setting ->accounts ->Send mail as
make a new email as defult
check Reply from the same address the message was sent to
all done!
i change code use new codes.

now show from my site



现在当你点击重播botton显示重播到用户电子邮件



now when you click replay botton show replay to user email

<?php
include "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 = "yourmail@gmail.com"; 
$mail->Password = "xxxxxxxxx";
$mail->addReplyTo("useremail@gmail.com","user");
$mail->SetFrom("useremail@gmail.com","My Site");
$mail->Subject = "Your Gmail SMTP Mail";
$mail->Body = "Hi, your first SMTP mail via gmail server has been received.";
$mail->AddAddress("yourmail@gmail.com");
 if(!$mail->Send()){
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
    echo "Message has been sent";
}
?>

这篇关于PHPMailer - gmail smtp无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆