PHP邮件发送代码不工作
我试图使用这种编码,但它不是在处理,也没有输出任何错误PHP邮件发送代码不工作,php,Php,我试图使用这种编码,但它不是在处理,也没有输出任何错误 function send_email($subject='Activate Your Account', $html_content, $text_content, $headers) { $en['email'] = 'test@email.com'; $to = $en['email']; $en['memb_id'] = '39'; $en['confcode'] = '69696969';
function send_email($subject='Activate Your Account', $html_content, $text_content, $headers) {
$en['email'] = 'test@email.com';
$to = $en['email'];
$en['memb_id'] = '39';
$en['confcode'] = '69696969';
$en['user'] = 'couple';
$text_content = "Confirm Your domain.com Account\r\n";
$text_content.= "UserName: " . $en['user'] . "\r\n";
$text_content.= "Activate Your Account by visiting this link below:\r\n";
$text_content.= "http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "\r\n";
$text_content.= "\r\n";
$text_content.= "______________________\r\n";
$text_content.= "Thanks,\r\n";
$text_content.= "Staff";
$html_content = "<html><body><h1>Confirm Your domain.com Account</h1>";
$html_content.= "<p>UserName: " . $en['user'] . "<br>";
$html_content.= "Activate Your Account by visiting this link below:<br>";
$html_content.= "<a href=http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . ">http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "</a>";
$html_content.= "</p>";
$html_content.= "______________________<br>";
$html_content.= "Thanks,<br>";
$html_content.= " Staff";
$html_content.= "</body></html>";
$mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x';
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n";
$headers.= "Content-Transfer-Encoding: 7bit\r\n";
$body = "This is a multi-part message in mime format.\n\n";
$body.= "--$mime_boundary\n";
$body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n";
$body.= "Content-Transfer-Encoding: 7bit\n\n";
$body.= $text_content;
$body.= "\n\n";
$body.= "--$mime_boundary\n";
$body.= "Content-Type: text/html; charset=\"UTF-8\"\n";
$body.= "Content-Transfer-Encoding: 7bit\n\n";
$body.= $html_content;
$body.= "\n\n";
$body.= "--$mime_boundary--\n";
$headers.= 'From: <support@domain.com>' . "\r\n";
$headers.= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n";
$headers.= 'Date: '.date('n/d/Y g:i A')."\r\n";
$headers.= 'Reply-To: <support@domain.com>' . "\r\n";
return mail($to, $subject, $body, $headers);
echo $to;
echo $subject;
echo $body;
echo $headers;
}
函数发送电子邮件($subject='Activate Your Account',$html\u content,$text\u content,$headers){
$en['email']='test@email.com';
$to=$en['email'];
$en['memb_id']='39';
$en['confcode']='6969';
$en['user']='couple';
$text\u content=“确认您的domain.com帐户\r\n”;
$text\u content.=“用户名:”.$en['user']。“\r\n”;
$text\u content.=“通过访问下面的链接激活您的帐户:\r\n”;
$text_content.=”http://www.domain.com/confirm/“$en['memb_id']”/“$en['confcode']”.“\r\n”;
$text\u content.=“\r\n”;
$text\u content.=“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\r\n”;
$text\u content.=“谢谢,\r\n”;
$text_content.=“Staff”;
$html\u content=“确认您的domain.com帐户”;
$html_content.=“用户名:”.$en['user'].“
”;
$html_content.=“通过访问以下链接激活您的帐户:
”;
$html_内容=“”;
$html_content.=“”;
$html\u content.=“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;
$html_content.=“谢谢,
”;
$html_content.=“Staff”;
$html_内容=“”;
$mime_boundary='Multipart_boundary_x'.md5(time()).'x';
$headers=“MIME版本:1.0\r\n”;
$headers.=“内容类型:多部分/可选;边界=\”$mime\U边界\“\r\n”;
$headers.=“内容传输编码:7bit\r\n”;
$body=“这是mime格式的多部分消息。\n\n”;
$body.=“--$mime\U边界\n”;
$body.=“内容类型:文本/普通;字符集=\”字符集=美国ascii \“\n”;
$body.=“内容传输编码:7bit\n\n”;
$body.=$text\u内容;
$body.=“\n\n”;
$body.=“--$mime\U边界\n”;
$body.=“内容类型:text/html;字符集=\“UTF-8\”\n”;
$body.=“内容传输编码:7bit\n\n”;
$body.=$html\u内容;
$body.=“\n\n”;
$body.=“--$mime\U边界--\n”;
$headers.='From:'。“\r\n”;
$headers.=“X-Sender-IP:$\u服务器[服务器地址]\r\n”;
$headers.='Date:'.Date('n/d/Y g:i A')。“\r\n”;
$headers.=“回复:”。“\r\n”;
返回邮件($to、$subject、$body、$headers);
echo$to;
受试者;
回声体;
echo$headers;
}
最后一点让我感到困惑:
return mail($to, $subject, $body, $headers);
echo $to;
echo $subject;
echo $body;
echo $headers;
您知道那些echo
语句都不会被执行,因为它们在返回之后,对吗
尝试使用error\u log
验证脚本中的步骤,如果您没有尝试过,则查看错误日志本身。最后一位让我感到困惑:
return mail($to, $subject, $body, $headers);
echo $to;
echo $subject;
echo $body;
echo $headers;
您知道那些echo
语句都不会被执行,因为它们在返回之后,对吗
尝试使用error\u log
来验证脚本中的步骤,或者查看错误日志本身(如果尚未尝试过)。使用。别让自己头疼了
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
使用。别让自己头疼了
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
来,我给你修的。我检查过了,效果很好。还要确保您的主机支持mail()函数。如果未启用SMTP,则您将无法确保发送邮件
修订代码:
<?php
function send_email($subject='Activate Your Account') {
$en['email'] = 'test@email.com';
$to = $en['email'];
$en['memb_id'] = '39';
$en['confcode'] = '69696969';
$en['user'] = 'couple';
$text_content = "Confirm Your domain.com Account\r\n";
$text_content.= "UserName: " . $en['user'] . "\r\n";
$text_content.= "Activate Your Account by visiting this link below:\r\n";
$text_content.= "http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "\r\n";
$text_content.= "\r\n";
$text_content.= "______________________\r\n";
$text_content.= "Thanks,\r\n";
$text_content.= "Staff";
$html_content = "<html><body><h1>Confirm Your domain.com Account</h1>";
$html_content.= "<p>UserName: " . $en['user'] . "<br>";
$html_content.= "Activate Your Account by visiting this link below:<br>";
$html_content.= "<a href=http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . ">http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "</a>";
$html_content.= "</p>";
$html_content.= "______________________<br>";
$html_content.= "Thanks,<br>";
$html_content.= " Staff";
$html_content.= "</body></html>";
$mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x';
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n";
$headers.= "Content-Transfer-Encoding: 7bit\r\n";
$body = "This is a multi-part message in mime format.\n\n";
$body.= "--$mime_boundary\n";
$body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n";
$body.= "Content-Transfer-Encoding: 7bit\n\n";
$body.= $text_content;
$body.= "\n\n";
$body.= "--$mime_boundary\n";
$body.= "Content-Type: text/html; charset=\"UTF-8\"\n";
$body.= "Content-Transfer-Encoding: 7bit\n\n";
$body.= $html_content;
$body.= "\n\n";
$body.= "--$mime_boundary--\n";
$headers.= 'From: <support@domain.com>' . "\r\n";
$headers.= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n";
$headers.= 'Date: '.date('n/d/Y g:i A')."\r\n";
$headers.= 'Reply-To: <support@domain.com>' . "\r\n";
return mail($to, $subject, $body, $headers);
}
?>
希望有帮助。让我们知道。这里,我为您修好了。我检查过了,效果很好。还要确保您的主机支持mail()函数。如果未启用SMTP,则您将无法确保发送邮件
修订代码:
<?php
function send_email($subject='Activate Your Account') {
$en['email'] = 'test@email.com';
$to = $en['email'];
$en['memb_id'] = '39';
$en['confcode'] = '69696969';
$en['user'] = 'couple';
$text_content = "Confirm Your domain.com Account\r\n";
$text_content.= "UserName: " . $en['user'] . "\r\n";
$text_content.= "Activate Your Account by visiting this link below:\r\n";
$text_content.= "http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "\r\n";
$text_content.= "\r\n";
$text_content.= "______________________\r\n";
$text_content.= "Thanks,\r\n";
$text_content.= "Staff";
$html_content = "<html><body><h1>Confirm Your domain.com Account</h1>";
$html_content.= "<p>UserName: " . $en['user'] . "<br>";
$html_content.= "Activate Your Account by visiting this link below:<br>";
$html_content.= "<a href=http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . ">http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "</a>";
$html_content.= "</p>";
$html_content.= "______________________<br>";
$html_content.= "Thanks,<br>";
$html_content.= " Staff";
$html_content.= "</body></html>";
$mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x';
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n";
$headers.= "Content-Transfer-Encoding: 7bit\r\n";
$body = "This is a multi-part message in mime format.\n\n";
$body.= "--$mime_boundary\n";
$body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n";
$body.= "Content-Transfer-Encoding: 7bit\n\n";
$body.= $text_content;
$body.= "\n\n";
$body.= "--$mime_boundary\n";
$body.= "Content-Type: text/html; charset=\"UTF-8\"\n";
$body.= "Content-Transfer-Encoding: 7bit\n\n";
$body.= $html_content;
$body.= "\n\n";
$body.= "--$mime_boundary--\n";
$headers.= 'From: <support@domain.com>' . "\r\n";
$headers.= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n";
$headers.= 'Date: '.date('n/d/Y g:i A')."\r\n";
$headers.= 'Reply-To: <support@domain.com>' . "\r\n";
return mail($to, $subject, $body, $headers);
}
?>
希望有帮助。让我们知道。您确定您的服务器上配置了邮件服务器吗?如果没有,那就是问题所在。你能详细说明它在做什么吗?你确定所有变量都设置正确吗?例如:您有$header到$header是的,我的邮件服务器配置正确。我一直在使用旧的mail()代码,我正在尝试升级到可以执行html&text的功能。您确定您的服务器上配置了邮件服务器吗?如果没有,那就是问题所在。你能详细说明它在做什么吗?你确定所有变量都设置正确吗?例如:您有$header到$header是的,我的邮件服务器配置正确。我一直在使用旧的mail()代码,我正在尝试升级到可以处理html和文本的东西