[英]checking whether my mail has been sent or not
<?php
@require_once"Mail.php";
$from="from email"; //enter email of sender
$to="recepient email"; //enter to email
$subject="subject";
$body="content";
$host="ssl://smtp.gmail.com";
$port="465";
$username="your gmail account user name";
$pwd="your gmail account password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$headers["Content-Type"] = 'text/html; charset=UTF-8';
$smtp = @Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $pwd));
//Send Email using pear sned option
$mail = @$smtp->send($to, $headers, $body);
//If any errors occurs
if (@PEAR::isError($mail)) {
("<p>" . $mail->getMessage() . "</p>");
}
else {
echo("<p>Message successfully sent!</p>");
}
?>
Adding @ reduce some error but still have three errors are coming they are: 添加@减少了一些错误,但仍有三个错误:
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Net\SMTP.php on line 491
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\Net\\SMTP.php on line 265 严格标准:非静态方法PEAR :: isError()不应该静态调用,假设来自第265行的C:\\ xampp \\ php \\ pear \\ Net \\ SMTP.php中的不兼容上下文中的$ this
Strict Standards: Non-static method PEAR::raiseError() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\Net\\SMTP.php on line 267 严格标准:非静态方法PEAR :: raiseError()不应该静态调用,假设$ 26来自267行C:\\ xampp \\ php \\ pear \\ Net \\ SMTP.php中的不兼容上下文
You could check whether the mail was successfully handed over to the MTA, you can't really detect or check if the mail was successfully delivered to the recipient . 您可以检查邮件是否已成功移交给MTA, 您无法检测或检查邮件是否已成功传递给收件人 。 That is a different case. 这是一个不同的情况。
To check whether the mail was sent : 要检查邮件是否已发送:
if (mail('abc@gmail.com',$subject,$body,'From: me@example.org'))
return true;
else
return false;
So your function will be : 所以你的功能将是:
function email($to,$subject,$body)
{
if (mail('abc@gmail.com',$subject,$body,'From: me@example.org'))
return true;
else
return false;
}
Since mail function always return boolean value, tt can be simplified as : 由于mail函数总是返回布尔值,因此tt可以简化为:
function email($to,$subject,$body)
{
return mail('abc@gmail.com',$subject,$body,'From: me@example.org');
}
Alternately if you have set reply-to in your mail header, then you can check for any bounced mail which will let you say with certainty that a message hasn't been delivered. 或者,如果您在邮件标题中设置了回复,则可以检查是否有任何退回邮件,这样可以确定邮件尚未发送。
You either have to install a mailserver for xampp, eg Mercury . 您必须为xampp安装邮件服务器,例如Mercury 。 Or you have to enter your (external) SMTP credentials into your php.ini
. 或者您必须在php.ini
输入(外部)SMTP凭据 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.