我正在使用班级PHPMailer通过SMTP发送邮件:
<?php
require 'php_mailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.dfgdfgdfg.de'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'dfgdfg'; // SMTP username
$mail->Password = 'dfgsdfgdsfg'; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'community@fdgdfg.de';
$mail->FromName = 'dfgdfgdg';
$mail->AddAddress('interview@dfgdfg.de', 'Udo'); // Add a recipient
$mail->AddBCC('bcc@example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'HTML-Mail mit Logo';
$mail->Body = 'Nachfolgend das <b>Logo</b>';
$mail->AltBody = 'Aktiviere HTML, damit das Logo angezeigt wird';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
?>
我的问题:
谢谢! 亚历
答案 0 :(得分:2)
您正在设置PHPMailer以与SMTP进行交互,因此我猜它会等待它完成。这不是最佳选择,因为正如您所说,在SMTP响应之前您将阻止PHP脚本。
最好通过localhost发送:设置PHPMailer使用sendmail,它通常是本地exim4或postfix的包装器,然后将为您处理邮件。这样做要好得多,因为本地服务器将处理任何可能的临时错误,并在以后重试。 PHP赢了。
您可能还想探索其他选项,例如Mandrill或Sendgrid来完成这项工作,特别是如果您进行大量邮寄或批量邮寄。
答案 1 :(得分:1)
发送到很多邮件的最佳方式是什么(相同的Mailtext,只有 称谓是不同的(Hello $ NAME)?
您可以执行以下操作:设置名称。
// rest of code first
$mail->AddAddress("you@example.com")
$ids = mysql_query($select, $connection) or die(mysql_error());
while ($row = mysql_fetch_row($ids)) {
$mail->AddBCC($row[0]);
}
$mail->Send();//Sends the email
您可以在正文中添加特殊字符串'name_here',并将$name
与str_replace函数放在一起
Is the PHP script waiting until every mail is delivered? Because sometimes I want to send a mail to some hundreds people, when a user is doing an action on the website. so this user cant wait of course, until all those mail were sent succesful!
根据我的知识,你必须等待。
如何做str_replace?假设您的电子邮件正文如下
$body = " Dear %first_name%,
other stuff goes here....... ";
$body = str_replace("%first_name%", $first_name, $body);
上面的将使用您提供的名称($ first_name)替换%first_name%。