Php 邮件不工作,没有发送两封电子邮件
我有一个可以识别级别的脚本,并且我添加了警报,以告知我是否已通过代码。这两个电子邮件地址正在反映。我想分别发送两封电子邮件,但我的收件箱不工作。我已经查过我的垃圾邮件了 我有什么遗漏吗Php 邮件不工作,没有发送两封电子邮件,php,email,Php,Email,我有一个可以识别级别的脚本,并且我添加了警报,以告知我是否已通过代码。这两个电子邮件地址正在反映。我想分别发送两封电子邮件,但我的收件箱不工作。我已经查过我的垃圾邮件了 我有什么遗漏吗 function emaillog($to,$id,$subject,$message){ include("dbconnect.php"); mysql_query("INSERT INTO emlog(mm,tt,ss,rr) VALUES('$message','$to','$subject','$id')
function emaillog($to,$id,$subject,$message){
include("dbconnect.php");
mysql_query("INSERT INTO emlog(mm,tt,ss,rr) VALUES('$message','$to','$subject','$id')");
}
if($level == 1){
$assignedtowho_email_result = mysql_query("SELECT Email FROM sheet1 WHERE id IN(SELECT assignedtowho FROM tbl_one WHERE id =$id)");
while($row_email=mysql_fetch_array($assignedtowho_email_result)){
$assignedtowho_email=$row_email['Email'];
}
// Email Sending department
$to = $senderEmail;
$subject = "Refferal status updated by recieving r";
$message = "Your status has been updated by ";
$from = "info@test.co.za";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
emaillog($to,$id,$subject,$message);
$message_alert="Sender mail sent: ".$to;
echo '<script>alert("'.$message_alert.'")</script>';
//echo "Mail Sent.";
// Email Recieving department
$to = $assignedtowho_email;
$subject = "Refferal status updated ";
$message = "Your refferal status has been updated";
$from = "info@test.co.za";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
emaillog($to,$id,$subject,$message);
$message_alert_2="Assigned mail sent: ".$to;
echo '<script>alert("'.$message_alert_2.'")</script>';
//echo "Mail Sent.";
}
要求
为了使邮件功能可用,PHP必须在编译时访问系统上的sendmail二进制文件。如果您使用其他邮件程序,如qmail或postfix,请确保使用附带的相应sendmail包装器。PHP将首先在您的路径中查找sendmail,然后在以下路径中查找:/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib。强烈建议从您的路径提供sendmail。此外,编译PHP的用户必须具有访问sendmail二进制文件的权限
确保您具有所有要求和SMTP服务器
因此,邮件功能支持。是否可以更改取决于您的操作系统和PHP版本
你可以看到所有这些[这里][1]
在ChangeLog侧
如果您使用的是Windows,则必须使用PEAR Mail。İt's
对于Ubuntu和Centos等Linux操作系统,必须确保配置php.ini和apache/httpd.ini
您可以在每个操作系统上使用此选项
<?php # Is the OS Windows or Mac or Linux
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
$eol="\r\n";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
$eol="\r";
} else {
$eol="\n";
} ?>
<?php
# File for Attachment
$f_name="../../letters/".$letter; // use relative path OR ELSE big headaches. $letter is my file for attaching.
$handle=fopen($f_name, 'rb');
$f_contents=fread($handle, filesize($f_name));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
$f_type=filetype($f_name);
fclose($handle);
# To Email Address
$emailaddress="user@example.com";
# Message Subject
$emailsubject="Heres An Email with a PDF".date("Y/m/d H:i:s");
# Message Body
ob_start();
require("emailbody.php"); // i made a simple & pretty page for showing in the email
$body=ob_get_contents(); ob_end_clean();
# Common Headers
$headers .= 'From: Jonny <jon@example.com>'.$eol;
$headers .= 'Reply-To: Jonny <jon@example.com>'.$eol;
$headers .= 'Return-Path: Jonny <jon@example.com>'.$eol; // these two to set reply address
$headers .= "Message-ID:<".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name=\"".$letter."\"".$eol; // sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$letter."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;
# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "If you are reading this, please update your email-reading-software.".$eol;
$msg .= "+ + Text Only Email from Genius Jon + +".$eol.$eol;
# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
# SEND THE EMAIL
ini_set(sendmail_from,'from@example.com'); // the INI lines are to force the From Address to be used !
mail($emailaddress, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);
?>
使用SMTP,您应该可以。而不是使用邮件。。。直接使用$mailResult=mail。。。。然后检查$mailResult是否为真,如果为真,则不是php失败,而是邮件服务器失败,可能您没有打开端口25或已定义的端口或类似端口检查smtp设置1。一定要检查邮件的返回值。若它是假的,那个么邮件就不会被放入队列,你们需要找出原因。2.若返回值为true,那个么邮件在队列中,但它并没有被发送,您还有其他问题需要解决。直到你处理了这个问题,你才知道你的问题是什么。