2015-05-29 69 views
3

送我有一個簡單的腳本,在我的任何其他服務器工作正常,但在那一個我需要的,它不...郵件沒有得到通過PHP

<?php 
$name = $_POST['Name']; 
$email = $_POST['Email']; 
$phone = $_POST['Phone']; 
$message = $_POST['Message']; 

$formcontent="Name: $name \n Email: $email \n Phone No: $phone \n Services: $services \n Message: $message"; 
$recipient = "[email protected]"; 
$subject = "Client Details"; 
$mailheader = "From: $email \r\n"; 
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
echo "Thank You!" . " -" . "<a href='../contact.html' style='text-decoration:none;color:#ff0099;'>Return Home</a>"; 
?> 

當我試圖提交通過形式聯繫信息,它給出了一個錯誤

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\Inetpub\vhosts\momentsworld.com\httpdocs\script\quick_query.php on line 17 

雖然同腳本適用於其他服務器罰款... plz幫助

+0

你正在本地服務器上運行它? –

+1

您需要在服務器上安裝MTA,如PostFix,qmail或sendmail。 – Daan

回答

0

試試這個:

<?php 
ini_set("SMTP","localhost"); 
ini_set("smtp_port",25); 
ini_set("sendmail_from","[email protected]"); 

$too = "[email protected]" ; 
$subject = "TEST" ; 
$message = "User message" ; 
$user_email = "[email protected]" ; 

$headers = "From: $user_email " ; 
$headers .= "Reply-To: $too " ; 
$headers .= "Return-Path: $too " ; 
$headers .= "X-Mailer: PHP/" . phpversion(). " " ; 
$headers .= 'MIME-Version: 1.0' . " " ; 
$headers .= 'Content-type: text/html; UTF-8' . " " ; 

if(mail ($too , $subject , $message , $headers)) echo 'SENT' ; 

?> 

即使它沒有在你的服務器上工作,你可以嘗試sendmail或Swiftmailer。檢查以下鏈接:

http://swiftmailer.org/docs/sending.html

0

您的服務器發送的郵件設置不configured.check服務器發送的郵件設置和啓用所有電子郵件發送的server.Another方式設置是使用smtp.Sample代碼將發送郵件如:

  1. 您的配置數組設置。

    $config = Array(
        'protocol' => 'smtp', 
        'smtp_host' => 'ssl://smtp.googlemail.com', 
        'smtp_port' => 465, 
        'smtp_timeout'=>'30', 
        'smtp_user' => '[email protected]', 
        'smtp_pass' => 'your gmail password', 
        'mailtype' => 'html', 
        'charset' => 'iso-8859-1', 
        '_smtp_auth' => TRUE, 
        'newline' => "\r\n" 
    ); 
    
  2. 初始化該配置設置,然後使用郵件發送代碼。

0

看來sendmail沒有在這臺服務器上配置。請讓IT人員安裝&爲您進行配置。除非郵件服務器沒有運行,否則您將無法發送電子郵件。另外,使用Gmail或其他SMTP提供程序將用於測試目的。大量的電子郵件,我想他們會將您的IP列入黑名單。

0

如果這是一臺Linux服務器,我們之前安裝的mailx,然後允許PHP郵件()標籤中使用。

此外,PHPMailer(如上所述)是另一個偉大的建議,利用SMTP到遠程服務器。

相關問題