使用PHPMailer发送电子邮件使用GoDaddy主机?
问题描述:
我目前正致力于为我的虚拟公司获取网站并运行,我一直在研究并且无法在任何地方找到答案。使用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。
任何人都有任何想法,我相信还有人想知道这件事。
答
您的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
感谢您的支持,我也应该注意到,我能够使用Gmail在本地主机服务器上发送电子邮件,但无法在官方网站上发送。这些设置似乎没有改变任何东西,我会打开一张支持凭单,看看他们有什么要说的。感谢您的快速响应, – JoshuaMicallef
您可能能够在登录后在您的主机帐户的某个位置找到正确的设置。 – Difster