我多年来一直在研究这个问题,但却找不到问题。希望有人能够帮助我。
我为我的邮件脚本制作了一个函数。该函数位于useful_functions.inc.php
<?php
include ('mailer/class.phpmailer.php');
function sendmail($mail)
{
$mail = new PHPMailer(true);
if (($_SERVER["REQUEST_METHOD"] == "POST") && $geslachtErr== "" && $voornaamErr== "" && $familienaamErr== "" && $emailErr== "" && $telErr== "" && $afileErr== "")
{
$full_name = "Sofie Doe";
$email = "sofie@gmail.com";
$subject = "HTML test mail.";
$text_message = "Hello ".$full_name.",<br /><br /> This is a test email in html.";
$message = "<html><body>";
$message .= "<table width='100%' bgcolor='#e0e0e0' cellpadding='0' cellspacing='0' border='0'>";
$message .= "<tr><td>";
$message .= "<table align='center' width='100%' border='0' cellpadding='0' cellspacing='0' style='max-width:650px; background-color:#fff; font-family:Verdana, Geneva, sans-serif;'>";
$message .= "<thead>
<tr height='80'>
<th colspan='4' style='background-color:#f5f5f5; border-bottom:solid 1px #bdbdbd; font-family:Verdana, Geneva, sans-serif; color:#333; font-size:34px;' >TEST</th>
</tr>
</thead>";
$message .= "</table>";
$message .= "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
try
{
$mail->IsSMTP();
$mail->isHTML(true);
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "STARTTLS";
$mail->Host = "mailout.one.com";
$mail->Port = 587;
$mail->AddAddress($email);
$mail->Username ="joe@gmail.com";
$mail->Password ="Password";
$mail->SetFrom("joe@gmail.com");
$mail->AddReplyTo("joe@gmail.com");
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
}
}
}
?>
我有一个表单test.php
。我用
<?php
include ('useful_functions.inc.php')
sendmail($mail);
?>
当我运行test.php
时,我一直收到HTTP ERROR 500
我用一个简单的html表单测试了确切的邮件程序并以相同的方式调用它并且它可以工作。
当我移除test.php
并移除sendmail($mail)
useful_function.inc.php
有效
为什么这不起作用?
答案 0 :(得分:1)
为什么不通过修改try{}
以包含$mail->Send();
来发送电子邮件“发送自己”?
你的“尝试”将成为:
try
{
$mail->IsSMTP();
$mail->isHTML(true);
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "STARTTLS";
$mail->Host = "mailout.one.com";
$mail->Port = 587;
$mail->AddAddress($email);
$mail->Username ="joe@gmail.com";
$mail->Password ="Password";
$mail->SetFrom("joe@gmail.com");
$mail->AddReplyTo("joe@gmail.com");
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
$mail->Send();
echo "Message Sent OK\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}