我如何发送像craigslist这样的电子邮件?

时间:2014-01-17 20:11:15

标签: php email

我正试图通过我的网站向用户发送电子邮件,就像craiglist一样。(例如,当用户A响应用户B发布的帖子时,会向用户A发送一封电子邮件,通知他用户A已回复然后,用户B可以按下他的电子邮件客户端中的回复按钮,如gmial / hotmail,回复邮件将被发送给用户A,任何进一步的通信将严格地在他们的2个之间,我的服务器只发送最初的电子邮件。)

目前我已经编写了一个功能,可以在成功注册后向用户发送电子邮件,我正在考虑修改它以便在上述情况下使用。但是,我不知道我会怎么做,因为我似乎无法改变我的函数中的FROM字段。

注意。我一般都是编程新手,现在正在使用PHP和Swiftmailer来处理我的电子邮件。

我的功能:

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');
    }
}

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

Craigslist在您发布时为您(@ craigslist.com)创建临时转发地址。因此,当第一个用户发送电子邮件时,它会被重新路由到另一个用户的电子邮件地址。

大多数SMTP提供商都不允许您冒充其他人的电子邮件地址。这是有道理的,因为您可能不希望有人无法保证能够从您的地址发送电子邮件。

答案 1 :(得分:0)

您在第一段中描述的不是craigslist的功能。 Craigslist将充当所有电子邮件通信之间的中间人,这样任何一方都不会知道其他人的真实电子邮件地址。

这显然非常复杂,需要拥有自己的邮件服务器,转换表和pop / smtp cron作业。

但是,如果你想完成你最初描述的内容,那就很容易了。只需使用Sender标头和ReplyTo标头,如下面的答案所述: Should I use the Reply-To header when sending emails as a service to others?

相关问题