2017-04-21 126 views
0

我已经创建了一个链接到具有表单的HTML文件的PHP脚本。我将我的Gmail电子邮件地址放在我的PHP文件中,并且不会发送给它。它甚至不在我的垃圾邮件文件夹中。我使用GoDaddy作为我的托管服务提供商。我将PHP文件中的电子邮件地址更改为AOL地址,并且按照我的意图工作。我的教授给我他的电子邮件,并发送给他。他们有GroupWise的电子邮件。我打电话给GoDaddy,他们说他们可以看到我的表单被提交给他们的服务器,但Google正在放弃它。下面是我的PHP代码:PHP脚本不会发送到Gmail,但其他电子邮件可以工作

<?php 
$myname = $_POST['name']; 
$myemail = $_POST['email']; 
$mytelephone = $_POST['telephone']; 
$what_service = $_POST['service']; 
$mycomments = $_POST['comments']; 

$to = '[email protected]'; 
$subject = 'Contact Us - My Company Example'; 
$msg = "Name: $myname\n" . 
"Service: $what_service\n" . 
"Telephone #: $mytelephone\n" . 
"Comments: $mycomments"; 
mail ($to, $subject, $msg, 'From:' . $myemail); 

echo '<p>Thank you for contacting us!</p>'; 
echo 'Your Name: ' . $myname . '<br>'; 
echo 'Your E-Mail: ' . $myemail . '<br>'; 
echo 'Your Telephone: ' . $mytelephone . '<br>'; 
echo 'Your Service: ' . $what_service . '<br>'; 
echo 'Your Comments: ' . $mycomments; 
?> 
+2

你怎么知道它没有工作? '但其他电子邮件工作“,那么它必须为所有人工作。检查垃圾邮件以及 –

回答

0

你必须定义一个SMTP协议设置发送邮件到Gmail ...

这是一种方式与PHP PEAR

// Pear Mail Library 
require_once "Mail.php"; 

$from = '<[email protected]>'; //change this to your email address 
$to = '<[email protected]>'; // change to address 
$subject = 'Insert subject here'; // subject of mail 
$body = "Hello world! this is the content of the email"; //content of mail 

$headers = array(
    'From' => $from, 
    'To' => $to, 
    'Subject' => $subject 
); 

$smtp = Mail::factory('smtp', array(
     'host' => 'ssl://smtp.gmail.com', 
     'port' => '465', 
     'auth' => true, 
     'username' => '[email protected]', //your gmail account 
     'password' => 'snip' // your password 
    )); 

// Send the mail 
$mail = $smtp->send($to, $headers, $body); 

做到这一点如果你使用Gmail SMTP记得要[在你的Gmail帐户中启用SMTP],在设置下

+0

感谢您的代码。你能告诉我梨是什么吗?另外,如果我为某人制作网站,他们必须给我他们的密码?如果由于某种原因,他们的客户端有Gmail,开发者会做什么? –

+0

从[github](https://github.com/pear/Mail)或[php.net](https://pear.php.net/package/Mail/download)获取梨子邮件库 –

相关问题