获取用户的CC副本邀请电子邮件

时间:2009-09-16 02:30:57

标签: php

以下代码效果很好。它允许用户通过电子邮件将我的网站推荐发送给朋友列表。

对于收到以下电子邮件的每个人,我希望收到一封包含该人电子邮件的电子邮件,以及向他们发送邮件的人的姓名。如果我的电子邮件地址是john@site.com,我可以使用哪些代码来执行此操作?

提前致谢,

约翰

$msg = "<html><body>Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use <a href='http://www.site.com/'>Site.com</a>.<a href='http://www.site.com/'>Site.com</a><br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
mail($email, $subject,$msg,$headers);
}

1 个答案:

答案 0 :(得分:4)

$msg = "<html><body>Hello, your friend ".htmlspecialchars($_POST['sendername'])." recommends that you use <a href='http://www.site.com/'>Site.com</a>.<a href='http://www.site.com/'>Site.com</a><br><br><img src='http://site.com/images/blacklogo.PNG'></body></html>";
$subject = "Try out Site.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "CC: foo@example.com\r\n";
$headers .= "BCC: foo@example.com\r\n";
$headers .= 'From: ' . $_POST['sendername'] . "\r\n";
foreach($_POST['email'] as $email){
    mail($email, $subject,$msg,$headers);
}

不要乱用原始标头,而应考虑使用许多优秀的API之一,例如SwiftmailerPHPMailerZend_Mail来命名三个。 Zend_Mail示例:

$mail = new Zend_Mail();
$mail->setBodyHtml('<p>hello</p>');
$mail->setFrom('foo@example.com', 'foo@example.com');
$mail->setSubject('Test Subject');
$mail->addTo('foo@example.com', 'Test');
$mail->addCc('foo@example.com', 'Another Test');
$mail->addBcc('foo@example.com', 'Another Test');
$mail->send();