【发布时间】:2019-07-27 00:17:45
【问题描述】:
我开始在我的网站上使用 PHPMailer 来设置联系表格(用户 -> 我自己的电子邮件帐户)。电子邮件发送过程看起来一切正常,但是当我想回复用户的电子邮件时遇到了问题。
似乎从我的网站发送电子邮件的电子邮件地址是我的,通过 SMTP 配置 -> 我可以接受。
我为 setFrom 和 addReplyTo 方法都定义了用户的电子邮件地址作为参数,以便能够从 Gmail 回复他的电子邮件,并发送我的答案到提供的电子邮件地址。
但是,当我点击 Gmail 上的“回复”时,我和用户都会收到我的回复。
我想我真的错过了一些东西,和/或误解了上述这些方法的目的。
我尝试将 addReplyTo 放在 setFrom 上方,如 there 所述,但看起来它并没有改变任何东西。
我有点纠结我还能做什么,我现在只使用 PHP 4 个月,还有一些东西仍然缺失,尤其是关于这个问题。
//class Mail
public function sendMail ()
{
//Instantiation and passing "true" enables exceptions
$mail = new PHPMailer(true);
$msg = utf8_encode(wordwrap($this->message, 70, "\r\n"));
try {
//Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'my_email_address@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
//Recipients
//Jon Doe <my_email_address@gmail.com(?)>
$mail->setFrom($this->mail, $this->first_name . ' ' . $this->last_name);
//User's email address
$mail->addReplyTo($this->mail);
$mail->addAddress('my_email_address+ALIAS@gmail.com');
// Content
$mail->isHTML(true);
//contact@domain.com : Jon Doe
$mail->Subject = 'contact@domain.com : ' . $this->first_name . ' ' . $this->last_name;
$mail->Body = $msg;
$mail->AltBody = $msg;
$mail->send();
} catch (Exception $e) {
//False need for my contact.php webpage if email cannot be sent
if (!empty($e->getMessage())) {
$_POST['success'] = false;
}
}
}
//contact.php
if (!empty($_POST['last_name']) && !empty($_POST['first_name']) && !empty($_POST['mail']) && !empty($_POST['message']) && isset($_POST['g-recaptcha-response'])) {
$first_name = htmlentities($_POST['first_name']);
$last_name = htmlentities($_POST['last_name']);
$mail = htmlentities($_POST['mail']);
$message = htmlentities($_POST['message']);
$contact = new Contact($first_name, $last_name, $mail, $message);
//Checking if everything's fine about form submission
if ($contact->isBool()) {
$mail = new Mail($contact);
$mail->sendMail();
//If something's wrong with the mailing process
if (isset($_POST['success'])) {
//Just some text to display to inform the user
$error_email['email_sent'] = "Foo";
} else {
//Just some text to display to inform the user
$success = "Bar";
}
} else {
$errors = $contact->getErrors();
}
}
这也是我的 Gmail 帐户关于邮件信息的屏幕截图:
我想通过我的 Gmail 帐户回复用户的电子邮件,并希望他是唯一能收到我回复的人。欢迎任何建议!
编辑:
今天经过多次尝试,当我点击 Gmail 上的“回复”按钮时,似乎只有我一个人收到了我的回复。用户没有收到任何东西...
【问题讨论】:
-
您能否在 gist/pastebin 中发布原始电子邮件标题,以便我们查看问题所在?
-
当然,这里是:pastebin.com/raw/R9EEvchS