I'm trying to send emails to users from my site just like how craiglist does it.(E.g When user A responds to a post by user B, an email gets sent out to user A informing him that user A has responded to his post.User B can then press the reply button in his email client like gmial/hotmail and the reply email will get sent to user A, and any further correspondence will be strictly between the 2 of them, with my server only sending the initial email.)
我正试图从我的网站向用户发送电子邮件,就像craiglist一样。(例如,当用户A响应用户B发布的帖子时,会向用户A发送一封电子邮件,通知他用户A已回复他的帖子然后,用户B可以按下他的电子邮件客户端中的回复按钮,如gmial / hotmail,回复邮件将被发送给用户A,任何进一步的通信将严格地在他们两个之间,我的服务器只发送初始电子邮件。 )
Currently i have written a function that sends out an email to the user upon successful registration and i am thinking of modifying it for use in the situation above. However, i am not sure how i would go about doing it as i can't seem to change the FROM field in my function.
目前我已经编写了一个功能,在成功注册后向用户发送电子邮件,我正在考虑修改它以便在上述情况下使用。但是,我不知道我将如何去做,因为我似乎无法改变我的函数中的FROM字段。
Note.I'm still new to programming in general and am currently using PHP, and Swiftmailer to handle my emails.
注意。我仍然是编程的新手,目前正在使用PHP和Swiftmailer来处理我的电子邮件。
My function:
function Activation($email,$token){
$transport=Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('test@gmail.com')
->setPassword('testpass');
$mailer=Swift_Mailer::newInstance($transport);
$message=Swift_Message::newInstance()
->setSubject('Account activation')
->setFrom(array('mymail@gmail.com' => '*Website name*'))
->setTo(array($email => $email))
->setBody("
Thank you for registering with us. Before we can activate your account one last step must be taken to complete your registration.
<br />
<br />
Please note - you must complete this last step to become a registered member. You will only need to visit this URL once to activate your account.
<br />
<br />
To complete your registration, please visit this URL:
<a href=http://localhost/test/account/activate.php?code=$token >http://localhost/test/account/activate.php?code=".$token."</a>
<br />
<br />
**** Does The Above URL Not Work? ****
If the above URL does not work, please go to the following link into your browser:
http://localhost/test/account/activate.php
<br />
<br />
Please be sure not to add extra spaces. You will need to type in your email and activation code on the page that appears when you visit the URL.
<br />
<br />
Your email is: ".$email."
<br />
Your Activation code is: ".$token."
<br />
<br />
If you are still having problems signing up please contact a member of our support staff at *contactemail*
<br />
<br />
All the best
","text/html");
if (!$mailer->send($message))
{
throw new Exception('Message sending failed');
}
}
Any help would be greatly appreciated.
任何帮助将不胜感激。
2 个解决方案
#1
0
What you describe in the first paragraph is not how craigslist functions. Craigslist will act as intermediary between ALL email communications so that neither party knows the others' true email address.
你在第一段中描述的不是craigslist的功能。 Craigslist将充当所有电子邮件通信之间的中介,以便任何一方都不知道其他人的真实电子邮件地址。
This is obviously very complex and requires having your own mail server, translation tables, and pop/smtp cron jobs.
这显然非常复杂,需要拥有自己的邮件服务器,转换表和pop / smtp cron作业。
However, if you want to accomplish what you first described, it is rather easy. Just use the Sender header and ReplyTo header as described in this answer: Should I use the Reply-To header when sending emails as a service to others?
但是,如果你想完成你最初描述的内容,那就很容易了。只需使用Sender标头和ReplyTo标头,如本答案中所述:在将电子邮件作为服务发送给其他人时,我应该使用Reply-To标头吗?
#2
0
Craigslist creates a temporary forwarding address for you (@craigslist.com) when you post. So, when the first user sends the e-mail, it is rerouted to the other user's e-mail address.
发布时,Craigslist会为您(@ craigslist.com)创建一个临时转发地址。因此,当第一个用户发送电子邮件时,它会被重新路由到另一个用户的电子邮件地址。
Most SMTP providers do not allow you to impersonate other people's e-mail addresses. This makes sense, since you probably would not want someone untrustworthy to be able to send e-mails from your address.
大多数SMTP提供商不允许您冒充其他人的电子邮件地址。这是有道理的,因为您可能不希望有人不值得信任,以便能够从您的地址发送电子邮件。
#1
0
What you describe in the first paragraph is not how craigslist functions. Craigslist will act as intermediary between ALL email communications so that neither party knows the others' true email address.
你在第一段中描述的不是craigslist的功能。 Craigslist将充当所有电子邮件通信之间的中介,以便任何一方都不知道其他人的真实电子邮件地址。
This is obviously very complex and requires having your own mail server, translation tables, and pop/smtp cron jobs.
这显然非常复杂,需要拥有自己的邮件服务器,转换表和pop / smtp cron作业。
However, if you want to accomplish what you first described, it is rather easy. Just use the Sender header and ReplyTo header as described in this answer: Should I use the Reply-To header when sending emails as a service to others?
但是,如果你想完成你最初描述的内容,那就很容易了。只需使用Sender标头和ReplyTo标头,如本答案中所述:在将电子邮件作为服务发送给其他人时,我应该使用Reply-To标头吗?
#2
0
Craigslist creates a temporary forwarding address for you (@craigslist.com) when you post. So, when the first user sends the e-mail, it is rerouted to the other user's e-mail address.
发布时,Craigslist会为您(@ craigslist.com)创建一个临时转发地址。因此,当第一个用户发送电子邮件时,它会被重新路由到另一个用户的电子邮件地址。
Most SMTP providers do not allow you to impersonate other people's e-mail addresses. This makes sense, since you probably would not want someone untrustworthy to be able to send e-mails from your address.
大多数SMTP提供商不允许您冒充其他人的电子邮件地址。这是有道理的,因为您可能不希望有人不值得信任,以便能够从您的地址发送电子邮件。