简体   繁体   English

如何通过“谢谢”消息将PHP脚本添加到自动响应中

[英]How can I add a PHP script to Auto-respond with a “thank you” message

I'm php newbie that just figured out how to use php with phpmailer to send email addresses of my users to my email address to be added to a newsletter. 我是php新手,只是想出了如何在phpmailer中使用php来将用户的电子邮件地址发送到我的电子邮件地址,以添加到新闻通讯中。

However, now I want to add a simple auto-respond script in php, so when users add their email to my guestlist it sends them an autoreply email to their email that says: 但是,现在我想在php中添加一个简单的自动响应脚本,因此,当用户将其电子邮件添加到我的访客列表时,它将向他们发送一封自动回复电子邮件,其内容为:

Thanks for signing up. 感谢您的注册。 [Picture of my logo] www.mysite.com [我的徽标图片] www.mysite.com

I've searched and searched, but I haven't been able to find a proper answer on how to create an autorespond script in php. 我已经搜索了,但是我还没有找到有关如何在php中创建自动响应脚本的正确答案。 Please let me know how I can accomplish this task. 请让我知道如何完成此任务。 Thank you! 谢谢!

<?php

$email = $_REQUEST['email'] ;

require("C:/inetpub/mysite.com/PHPMailer/PHPMailerAutoload.php");

$mail = new PHPMailer();

// set mailer to use SMTP
$mail->IsSMTP();

$mail->Host = "smtp.comcast.net"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myusername@comcast.net"; // SMTP username
$mail->Password = "*******"; // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25;                                    


$mail->From = $email;

// below we want to set the email address we will be sending our email to.
$mail->AddAddress("myemail@gmail.com", "Guestlist");

// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);

$mail->Subject = "A new member wishes to be added";

$message = $_REQUEST['message'] ;
$mail->Body = $email;
$mail->AltBody = $email;

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";

$mail2 = new PHPMailer();

// set mailer to use SMTP
$mail2->IsSMTP();

$mail2->Host = "smtp.comcast.net"; // specify main and backup server
$mail2->SMTPAuth = true; // turn on SMTP authentication
$mail2->Username = "myusername@comcast.net"; // SMTP username
$mail2->Password = "*******"; // SMTP password
$mail2->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail2->Port = 25;                                    


$mail2->From = $email;

// below we want to set the email address we will be sending our email to.
$mail2->AddAddress("$email");

// set word wrap to 50 characters
$mail2->WordWrap = 50;
// set email format to HTML
$mail2->IsHTML(true);

$mail2->Subject = "Thank you for joining";

$message = "Please stay tune for updates" ;

$message = $_REQUEST['message'] ;
$mail2->Body = $message;
$mail2->AltBody = $message;

if(!$mail2->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail2->ErrorInfo;
exit;
}

echo "Message has been sent";
?>

Update: 1 Ok, I figured out how to send auto-respond emails to users. 更新:1好的,我知道了如何向用户发送自动回复的电子邮件。 However, now the users are receiving messages with their own email address and the name Root user 但是,现在用户正在接收带有他们自己的电子邮件地址和Root用户名的邮件。

So what can I do to fix this problem so that users see my email address when they recevie auto-responses, and how can I make sure it says my name instead of root user? 那么,我该怎么办才能解决此问题,以便用户在收到自动回复时看到我的电子邮件地址,以及如何确保它说出我的姓名而不是root用户?

Do not use the submitter's email address as the from address - it won't work as it looks like a forgery and will fail SPF checks. 不要将提交者的电子邮件地址用作发件人的地址,因为它看起来像是伪造的,因此将无法通过SPF检查。 Put your own address as the From address, and add the submitter's address as a reply-to. 将您自己的地址作为发件人地址,并添加提交者的地址作为回复。

Using SMTPSecure = 'ssl' with Port = 25 is an extremely unusual combination, and very likely to be wrong. SMTPSecure = 'ssl'Port = 25是一种非常不寻常的组合,并且很可能是错误的。 ssl/465 and tls/587 are more usual. ssl / 465和tls / 587更常见。

To send multiple messages, you do not need to create a second instance - just re-use the same one. 要发送多个消息,您无需创建第二个实例-只需重复使用同一实例即可。 You can reset any individual properties you want (such as Body ) and clear addresses using $mail->clearAddresses() , then just call $mail->send() a second time. 您可以重置所需的任何单个属性(例如Body )并使用$mail->clearAddresses()清除地址,然后再次调用$mail->send()

It looks like you have based your code on an old example (try a new one ) - make sure you are using latest PHPMailer - at least 5.2.10. 看起来您的代码是基于旧示例(尝试使用新示例)-确保您使用的是最新的PHPMailer-至少为5.2.10。

add: 加:

echo "Message has been sent";
$mail = new PHPMailer();
$mail->From = 'myemail@gmail.com';

// below we want to set the email address we will be sending our email to.
$mail->AddAddress($email);

// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);

$mail->Subject = "Thanks for joining ...";

$message = "Thanks for joining...";
$mail->Body = $email;
$mail->AltBody = $email;

$mail->Send();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM