2015-06-16 24 views
0

我是新來的PHP和試圖發送電子郵件與PHP腳本。PHP代碼發送電子郵件與Smtp

我的確發生了變化 「的php.ini」 設置 SMTP = "in.mailjet.com" smtp_port= 25 auth_username="abc" auth_password="abc" sendmail_from = "[email protected]"

簡單HTML文件來調用PHP文件 form name="contactform" method="post" action="PHPMailer/email.php"
style="padding-left:5%;"> <td colspan="2" style="text-align:center"> <br> <input class="btn btn-info" type="submit" value="Download">

email.php文件

require 'class.phpmailer.php'; 
    $mail = new PHPMailer(true); 
    $mail->IsSMTP(); 
    $mail->Host="in.mailjet.com"; 
    $mail->SMTPAuth = true; 
    $mail->Username = 'abc'; 
    $mail->Password = 'abc'; 
    $mail->SetFrom('abc','Your Name'); 
    $mail->AddAddress('[email protected]fleet.com','Their Name'); 
    $mail->Subject = 'Your email from PHPMailer and Mailjet'; 
    $mail->MsgHTML('This is your email message."); 
    $mail->Send(); 

我想發送電子郵件f rom IIS服務器(測試服務器),但我無法發送請幫助我或讓我知道我缺少什麼。

謝謝

+2

以及它可以是任何一些事情,但SO語法highligher應該幫助你在倒數第二行發現一個不匹配的報價 – Steve

+0

對不起史蒂夫你能幫我解決這個問題嗎? – Jibran

+1

對於引用'......您的電子郵件信息的開始修復程序「);'應該是'...您的電子郵件信息');'請注意單個而不是雙引號 – Steve

回答

0

試試下面的代碼:

require 'class.phpmailer.php'; 

$mail = new PHPMailer(); 

$mail->isSMTP(); // send via SMTP 

//Enable SMTP debugging 
// 0 = off (for production use) 
// 1 = client messages 
// 2 = client and server messages 
//$mail->SMTPDebug = 2; 

$mail->Host = $host; //SMTP server 
$mail->Port = $port; //set the SMTP port; 587 for TLS 
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail 

if (strlen($username)) { 
    $mail->SMTPAuth = true; 
    $mail->Username = $username; 
    $mail->Password = $password; 
} else { 
    $mail->SMTPAuth = false; 
} 

$mail->From = $from; // FROM EMAIL 
$mail->FromName = $fromName; // FROM NAME 
$mail->addAddress($to); 
$mail->addReplyTo($from); 

$mail->IsHTML($html); 

$mail->Subject = $subject; // YOUR SUBJECT 
$mail->Body = $message; // YOUR BODY 
$mail->addAttachment($attachment); // YOUR ATTACHMENT FILE PATH 

if ($mail->send()) { 
    echo "Message Sent";exit; 
} else { 
    echo "Message Not Sent<br>"; 
    echo "Mailer Error: " . $mail->ErrorInfo;exit; 
} 

注:替換所有variables與你適當

+0

它將獲取$主機,$ port,$ username和$ password(來自php.ini) – Jibran

+0

@Jibran它的變量, ='25'或'456'或'587','$ username' ='您的電子郵件'和'$ password' ='您的密碼' –

+0

「仍然是空白頁。我在PHPMailer下保存email.php文件。更改了php.ini設置,但結果仍然相同。還有什麼我缺少在IIS服務器上運行此腳本「 – Jibran