将电子邮件从表单发送到Gmail帐户的最简单方法是什么?

时间:2015-03-01 18:07:08

标签: php forms email

我在网站上有一堆表单,当用户点击提交时,我想将这些信息发送到我的Gmail帐户。我正在使用的代码如下,但我遇到了问题。当我提交表格时,要么需要很长时间才能收到(比如提交表格后一小时),或者我根本没有收到电子邮件。

// Get values from form
$customerName  =$_POST['name'];
$customerPhone =$_POST['phone'];
$customerEmail =$_POST['email'];
$Year          =$_POST['year'];
$Make          =$_POST['make'];
$Model         =$_POST['model'];
$comments      =$_POST['comments'];

$to = "MyGmailAccount@gmail.com";
$subject = "Website Support Form";
$message = "Contact Details \r\n Name: " . $customerName . "\r\n Phone: " . $customerPhone . "\r\n Email: " . $customerEmail . "\r\r Information \r\n Year" . $Year. "\r\n Make: " . $Make . "\r\n Model: " . $Model . "\r\n Problem: " . $comments;

$from = "sendersEmail@whatever.com";
$headers = "From:" . $from . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; 

if(@mail($to,$subject,$message,$headers)) {
print "<script>document.location.href='http://www.mywebsite.com/success.php';</script>";
}else{
echo "Error! Please try again.";
{

0 个答案:

没有答案