【发布时间】:2018-11-22 18:54:51
【问题描述】:
这是我的代码,它运行良好,但我不希望它正常发送。我希望它使用 SMTP 身份验证发送。我真的不知道该怎么做。
<?php
if(!isset($_POST['to_emails'],$_POST['from_email'],$_POST['replyTo'],$_POST['comp_name'],$_POST['subject'])) {
$failure=true;
echo "Oops, insufficent mailing values posted";
}else{
foreach(explode(",",$_POST['to_emails']) as $index=>$email){
$email=trim($email);
$compname = $_POST['comp_name'];
$fromail = $_POST['from_email'];
$headers = 'From: ' . $compname . ' <' . $fromail .'>';
$headers .= "\r\nContent-Type: text/html; charset=ISO-8859-1";
$headers .= "\r\nReply-To: " . $_POST['replyTo'];
$headers .= "\r\nX-Mailer: PHP/" . phpversion();
$message = $_POST['message'];
$message = str_replace("&email&", $email, $message);
if(mail($email, $_POST['subject'], $message, $headers)){
echo "<font color='#FFFFB9'>{$index} Emailed: {$email}</font><br />";
}else{
$failure=true;
echo "Oops, something went wrong on email index $index to $email<br>";
}
}
}
?>
【问题讨论】:
-
你为什么不使用像 SwiftMailer 这样的库来为你处理所有困难的事情?