【发布时间】:2014-09-01 23:18:24
【问题描述】:
更新:这是我收到的错误:SMTP 连接()失败。 致命错误:未捕获的异常 'phpmailerException' 带有消息 'SMTP connect() failed。'
我正在使用一个名为 Frameworx 的预先存在的 php 框架。一切都很棒,但它不会发送电子邮件,我认为这是因为我使用的是 OpenShift,而且他们对邮件服务器非常严格。我需要使用 SendGrid,所以我试图使用 PHPMailer 来做到这一点。也许我对这一切都错了。但基本上,当我尝试发送邮件时,我得到的只是一个空白页。用户已创建。
这就是我所拥有的:
// Create a New Account Form
if (isset($_POST['submit']) && $_POST['submit'] == 'newAccount') {
// User Validations
if($_POST['usersName'] == '') {
$msgBox = alertBox("Your First and Last Name is required.", "<i class='fa fa-times-circle'></i>", "danger");
} else if($_POST['usersEmail'] == '') {
$msgBox = alertBox("A valid Email Address is required.", "<i class='fa fa-times-circle'></i>", "danger");
} else if($_POST['password'] == '') {
$msgBox = alertBox("A New Account Password is required.", "<i class='fa fa-times-circle'></i>", "danger");
} else if($_POST['password'] != $_POST['passwordr']) {
$msgBox = alertBox("Passwords do not match, please check your entries.", "<i class='fa fa-times-circle'></i>", "danger");
// Black Hole Trap to help reduce bot registrations
} else if($_POST['captcha'] != '') {
$msgBox = alertBox("An Error was encountered and the New Account could not be created.", "<i class='fa fa-times-circle'></i>", "danger");
} else {
// Set some variables
$dupEmail = '';
$newEmail = $mysqli->real_escape_string($_POST['usersEmail']);
// Check for Duplicate email
$check = $mysqli->query("SELECT 'X' FROM users WHERE usersEmail = '".$newEmail."'");
if ($check->num_rows) {
$dupEmail = 'true';
}
// If duplicates are found
if ($dupEmail != '') {
$msgBox = alertBox("There is all ready a User Account registered with that Email Address.", "<i class='fa fa-times-circle'></i>", "danger");
} else {
// Create the new account
$password = encryptIt($_POST['password']);
$usersName = $mysqli->real_escape_string($_POST['usersName']);
$joinDate = date("Y-m-d H:i:s");
$hash = md5(rand(0,1000));
$isActive = '0';
$stmt = $mysqli->prepare("
INSERT INTO
users(
usersEmail,
password,
usersName,
joinDate,
hash,
isActive
) VALUES (
?,
?,
?,
?,
?,
?
)");
$stmt->bind_param('ssssss',
$newEmail,
$password,
$usersName,
$joinDate,
$hash,
$isActive
);
$stmt->execute();
// Send out the email in HTML
require_once('class.phpmailer.php');
$mail = new PHPMailer(true);
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'https://api.sendgrid.com/'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'looloobs'; // SMTP username
$mail->Password = 'passowrd'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to // TCP port to connect to
$mail->From = 'militarypropertyproject@gmail.com';
$mail->FromName = 'Mailer';
$mail->addAddress('laurenrothlisberger@gmail.com', 'Joe User'); // Add a recipient
$mail->addReplyTo('info@example.com', 'Information');
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
$stmt->close();
// Clear the Form of values
$_POST['usersName'] = $_POST['usersEmail'] = $_POST['password'] = $_POST['passwordr'] = $_POST['captcha'] = '';
}
}
}
【问题讨论】:
-
如果您收到标题所暗示的 500 Internal Server 错误,请首先检查服务器的错误日志。
-
我承认对服务器日志了解不多,但是当我进入那里时,我看到的就是这些。 "[01/Sep/2014:19:48:18 -0400] "POST /login.php HTTP/1.1" 500 - "scoutmember-milpropertyproj.rhcloud.com/login.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0)壁虎/20100101 火狐/31.0"
-
该行将来自服务器的 access 日志……error 日志是不同的。
-
谢谢,尽管做了他们所说的所有事情来打开错误日志,但我似乎无法让他们显示。所以我想我必须等到明天能收到 OpenShift 的消息。谢谢
-
不要发布您的密码,尤其不要发布两次!
标签: php email openshift phpmailer sendgrid