通过php中的网站与smtp邮寄

时间:2017-08-01 13:49:50

标签: php email smtp gmail

我有一个代码,可以通过 Gmail SMTP发送电子邮件。

但是当我提交它有错误时,发送失败。

那么有人可以帮我处理代码吗?

if(isset($_POST['name']))
{
    $name=$_POST['name'];
    $email=$_POST['email'];
    $phone=$_POST['phone'];
    $exp=$_POST['exp'];

    $host = "ssl://smtp.gmail.com";
$username = "email@gmail.com";
$password = "password";
$port = "465";
    $to = "me@gmail.com";
    $subject = "Contact Form";
    $message = " Name: " . $name ."\r\n Email: " . $email . "\r\n Number: " . $phone . "\r\n Driving Experience:" . $exp ;

    $from = "" .$name. "( Driver )";
    $headers = "From:" . $from . "\r\n";
    $headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; 
    if(@mail($to,$subject,$message,$headers))
    {
      $text = "<span style='color:blue; font-size: 35px; line-height: 40px; margin: 10px;'>Your Message was sent successfully !</span>";
    }
    else
    {
        $text = "<span style='color:red; font-size: 35px; line-height: 40px; margin: 10px;'>Failed to send your request. Please try again Later.</span>";
    }
}
?>

谢谢!

0 个答案:

没有答案