简体   繁体   English

检查我的邮件是否已发送

[英]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.

相关问题 我的注册表格保存到数据库,并说已发送确认电子邮件,但我的邮件服务器反映没有发送电子邮件 - My registration formsaves to database and says confirmation email has been sent but my mail server reflects that no email is sent out 如何检查ajax请求是否已经通过Jquery发送? - How to check whether an ajax request has allready been sent with Jquery? 取消设置变量,而不检查其是否已被使用或声明 - Unset a variable without checking whether it has been already used or declared 发送电子邮件后更改 Div 中的文本? - Change Text In Div After E-Mail Has Been Sent? 知道队列中的邮件是否已发送 Laravel 5.4 - Know if Mail in queue has been sent Laravel 5.4 使用Zend_Mail时如何验证邮件是否已发送? - How to verify a mail has been sent when using Zend_Mail? 发送登录表单后未设置我的cookie - My cookies are not being set after the login form has been sent 在允许用户进入下一部分之前,检查表单验证是否已单击选项(单选按钮) - checking on form validation whether a choice has been clicked (radio button) before allowing user onto the next section 发件人的电子邮件ID为Yahoo ID时,尚未发送邮件 - Mail has not been sent when sender email-id was yahoo id DOM事件-发送电子邮件后开始下载 - DOM Event - start download after E-Mail has been sent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM