2017-06-15 59 views
0

我試圖讓我的HTML接觸形式與PHPMailer的工作,但是當我嘗試發送消息時,我無法連接到服務器:PHPMailer的不連接HTML/PHP

2017-06-15 10:39:15 SMTP ERROR: Failed to connect to server: (0) 2017-06-15 10:39:15 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

我正嘗試連接到SiteGround SMTP服務器。

表單代碼:

<form id="contact" action="mailer.php" method="post"> 
    <div class="left"> 
     <input type="text" placeholder="Name" required="required" name="name"/> 
     <input type="email" placeholder="Email" required="required" name="email"/> 
     <input type="text" placeholder="Subject" required="required" name="subject"/> 
    </div> 
    <div class="right"> 
     <textarea placeholder="Message" required="required" name="message"></textarea> 
    </div> 
    <div class="send-button cl"> 
     <button type="submit" name="submit">Send</button> 
    </div> 
</form> 

PHP代碼:

//Creating the message 
$message = 
'Name: '.$_POST['name'].'<br /> 
Subject: '.$_POST['subject'].'<br /> 
Email: '.$_POST['email'].'<br /> 
Message: '.$_POST['message'].' 
'; 

require 'phpmailer/PHPMailerAutoload.php'; 

// Instantiate Class 
$mail = new PHPMailer(); 

// Set up SMTP 
$mail->IsSMTP(); // enable SMTP 
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail 
$mail->Host = "mail.frankkreutzer.com"; 
$mail->Port = 465; // 587 | 465 
// $mail->IsHTML(true); 

// Authentication 
$mail->Username = "[email protected]"; 
$mail->Password = "password"; 

// Compose 
$mail->SetFrom($_POST['email'], $_POST['name']); 
$mail->Subject = $_POST['subject']; 
$mail->MsgHTML($message); 

// Send to 
$mail->AddAddress("[email protected]"); // Where to send it 

if(!$mail->Send()) { 
echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
echo "Message has been sent"; 
} 
+0

$ MAIL->從= 「發件人ID」 //失蹤? –

+0

所以你只是說要添加該行? – Frank

回答

0

只是固定的PHP代碼:

<?php 
require 'phpmailer/PHPMailerAutoload.php'; 

//Creating the message 
$message = 
'Name: '.$_POST['name'].'<br /> 
Email: '.$_POST['email'].'<br /><br /> 
Subject: '.$_POST['subject'].'<br /> 
Message: '.$_POST['message'].' 
'; 

// Instantiate Class 
$mail = new PHPMailer(); 

// Set up SMTP 
$mail->IsSMTP(); // enable SMTP 
// $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages 
only 
$mail->SMTPAuth = true; // authentication enabled 
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 465; // 587 | 465 
// $mail->IsHTML(true); 

// Authentication 
$mail->Username = "[email protected]"; 
$mail->Password = "password"; 

// Compose 
$mail->setFrom($_POST['email']); 
$mail->Subject = $_POST['subject']; 
$mail->MsgHTML($message); 

// Send to 
$mail->AddAddress("[email protected]"); // Where to send it 

if(!$mail->Send()) { 
echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
echo "Message has been sent. I'll get back to you as soon as possible!"; 
} 
?> 
相關問題