2017-04-21 122 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)獲取梨子郵件庫 –

相關問題