更新:这是我收到的错误:SMTP连接()失败。 致命错误:未收到异常'phpmailerException',并显示消息'SMTP连接()失败。'PHPMailer没有发送,没有给出错误抛出500错误
我正在使用一个名为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 = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addReplyTo('[email protected]', '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内部服务器错误所有。 – CBroe 2014-09-01 23:30:26
我承认并不知道很多关于服务器日志的知识,但是当我进去时,这就是我所看到的。 “[01/Sep/2014:19:48:18 -0400]”POST /login.php HTTP/1.1“500 - ”http://scoutmember-milpropertyproj.rhcloud.com/login.php“”Mozilla/5.0 Macintosh;英特尔Mac OS X 10.9; rv:31.0)Gecko/20100101 Firefox/31.0“ – looloobs 2014-09-01 23:51:47
该行将来自服务器的_access_日志... __error__日志是不同的 – CBroe 2014-09-01 23:54:50