2017-08-03 135 views
0

我目前正致力於爲我的虛擬公司獲取網站並運行,我一直在研究並且無法在任何地方找到答案。使用PHPMailer發送電子郵件使用GoDaddy主機?

當用戶註冊時,我希望他們收到一封電子郵件,提供公司簡介。下面是我使用的代碼(是的,在$ _SESSION變量並具有值

<?php 
session_start(); 

require '../../PHPMailer/PHPMailerAutoload.php'; 

$EmailUsername = $_SESSION['Username']; 
$EmailFirstName = $_SESSION['FirstName']; 
$EmailEmail = $_SESSION['Email']; 

$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'localhost'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = '#Password';       // SMTP password 
$mail->SMTPSecure = 'ssl';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 25;          // TCP port to connect to 

$mail->setFrom('[email protected]', 'No-Reply'); 
$mail->addAddress($EmailEmail, $EmailFirstName);  // Add a recipient 
$mail->addAddress('');    // Name is optional 
$mail->addReplyTo('', ''); 
$mail->addCC(''); 
$mail->addBCC(''); 

$mail->addAttachment('');   // Add attachments 
$mail->addAttachment(''); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Ozzie Transport Signup'; 
$mail->Body = "Hello, $EmailUsername. 
        <br><br> 
        Welcome to <b>Ozzie Transport.</b> A Virtual Trucking Company Utilising Truckers MP’s Multiplayer's Servers on Both American Truck Simulator and European Truck Simulator 2. 
        <br><br> 
        <b>Ozzie Transport</b> was founded by <i>Mr. Will Lads</i> and <i>Mr. Jacob Findlater</i>. Who where major assets to Ozzie Transport's Beginning. 
        <br><br> 
        Your Account is in the process of activation by our current Driver Manager. <i>Luc Jones</i>, You may log into your account using the Username and Password given in your Sign Up Application. 
        <br><br> 
        <b>Username:</b> <i>$EmailUsername.</i> 
        <br><br> 
        <b><i>If you have any questions, please reply to this email. We would be happy to hear from you.</i></b> 
        <br><br> 
        <b>Kind Regards</b> 
        <br><b><i>Joshua Micallef<br> 
        Chief Executive Officer - Ozzie Transport 
        "; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 

session_destroy(); 
//header("Location: ../../Login.php"); 

我每次運行它給了我下面的錯誤消息的代碼:消息無法sent.Mailer錯誤:SMTP連接()失敗。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

任何人都有任何想法,我相信還有人想知道這件事。

回答

0

您的GoDaddy帳戶應該爲您提供您需要連接到您的託管帳戶的主機名和端口號,以便您可以使用其電子郵件服務器發送電子郵件。

它看起來像這樣,但你必須與GoDaddy檢查你的帳戶的確切設置。

SMTP_SERVER: smtpout.secureserver.net (or alternatively relay-hosting.secureserver.net) 
SMTP_PORT: 465 //or 3535 or 80 or 25 
SMTP_AUTH: true //always 
SMTP_Secure: 'ssl' //only if using port 465 
+0

感謝您的支持,我也應該注意到,我能夠使用Gmail在本地主機服務器上發送電子郵件,但無法在官方網站上發送。這些設置似乎沒有改變任何東西,我會打開一張支持憑單,看看他們有什麼要說的。感謝您的快速響應, – JoshuaMicallef

+0

您可能能夠在登錄後在您的主機帳戶的某個位置找到正確的設置。 – Difster

相關問題