简体   繁体   English

php mail()函数不适用于gmail

[英]php mail() function not working with gmail

PFB my code PFB我的代码

<html>
    <head>
        <title> Your information</title>
    </head>
    <body>
    <?php

    $x = $_POST['yourname'];


    $email = $_POST['email'];
    $msg="Your Name is $x.";
    $to='abc@gmail.com';
    $sub='Your information';
    $header = "From: ". $x . " <" . $email . ">\r\n";
    ini_set("SMTP","smtp.gmail.com" );
    ini_set('sendmail_from', 'abc@gmail.com');
    //$email is entered as abc@gmail.com
    if(mail($to, $sub, $msg,'From:' . $email)){
        echo 'success';
    }
    else{
        echo 'failure';
    }


echo 'Thanks for submitting your information<br/>';
echo 'Your Name ' . $x . '<br/>' ;
echo 'Email ' . $email . '<br/>' ;
echo $msg;
?>
    </body>
</html>

i hqve configured my outlook 2007 with my gmail account(POP/SMTP). 我用我的gmail帐户(POP / SMTP)配置了Outlook 2007。 and the php.ini settings are SMTP= smtp.gmail.com smtp_port= 587. These settings also match with the outlook settings. 并且php.ini设置为SMTP = smtp.gmail.com smtp_port =587。这些设置也与Outlook设置匹配。

Still all i get is "failure" prinited on my browser. 我得到的仍然只是浏览器中显示的“失败”。 Please help. 请帮忙。

You will need to use "ssl" for sending emails from Gmail. 您需要使用“ ssl”从Gmail发送电子邮件。 YOu can download PhPmailer and can see the sample they provide for gmail. 您可以下载PhPmailer,并可以查看他们为gmail提供的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM