这是我的代码:
<?php
function smtp_mail($from, $to, $subject, $message, $headers="", $params=array()) {
$errno = "";
$errstr = "";
$smtpConnect = fsockopen("mail2.allramhosting.com", "25", $errno, $errstr, 20);
if (!empty($smtpConnect)) {
if ($params['use_html']) {
$extra_headers .= "MIME-Version: 1.0\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n";
}
$headers = "To: " . $to . "\nFrom: " . $from . "\nSubject: " . $subject . "\nDate: " . date('r') . "\n" . $extra_headers . $headers;
if (substr($headers, -1) == "\n") $headers = substr($headers, 0, -1); // Our last character should not be newline
//fputs($smtpConnect,"AUTH LOGIN" . $newLine);
//$smtpResponse = fgets($smtpConnect, 515);
//fputs($smtpConnect, base64_encode($username) . $newLine);
//$smtpResponse = fgets($smtpConnect, 515);
//fputs($smtpConnect, base64_encode($password) . $newLine);
//$smtpResponse = fgets($smtpConnect, 515);
fputs($smtpConnect, "HELO networkssms.com\r\n");
fputs($smtpConnect, "MAIL FROM: " . $from . "\r\n");
fputs($smtpConnect, "RCPT TO: " . $to . "\r\n");
fputs($smtpConnect, "DATA\r\n");
fputs($smtpConnect, $headers . "\r\n\r\n");
fputs($smtpConnect, $message . "\r\n.\r\n"); // send message and finish
fputs($smtpConnect,"QUIT" . $newLine);
fclose($smtpConnect);
return true;
}
return false;
}
$params['use_html'] = "yes";
$user_subject = "Ticket - Budget Notification";
$user_part = '<html><body>';
$user_part .= '<div style="background-color: #EEEEEE;border-bottom: 1px solid #DCDCDC;padding: 10px 10px 20px;width: 500px; float:left;font-size:12px;font-weight:bold;">';
$user_part1 = '<div style="width:500px;">';
$user_part1 .= '<div style="width:500px;background-color:#eeeeee;padding: 10px 0 20px;border-bottom:1px solid #dcdcdc;">';
$user_part1 .= '<div style="float:left;width:150px;color:#666666;margin-left:20px;font-size:12px;font-weight:bold;">';
$user_part1 .= '</div></div>';
$user_part1 .= '<div style="width:450px;background-color:#eeeeee;padding: 10px 0 20px;border-bottom:1px solid #dcdcdc; height:auto; float:left;font-size:12px;margin-left:50px; font-weight:bold;">';
$user_part3 = '</div></div></div>';
$user_part3 .= '</body></html>';
$user_center_part1 = '';
$user_center_part = 'The following Tickets are reached its budget ,';
$user_center_part2='<div style="float:left;width:auto;color:#000000;font-size:12px;margin-left:75px; font-weight:bold; height:auto; margin-top:10px;">Ticket #10 reached 100% of its budget</div>';
$user_to = 'galtech.staffs@gmail.com';
$user_center_part1 = 'Dear Admin ,';
$user_message = $user_part.$user_center_part1.$user_part1.$user_center_part.$user_center_part2.$user_part3;
if (!smtp_mail("noreply@networkssms.com", $user_to, $user_subject, $user_message,"",$params)){
mail($user_to, $user_subject, $user_subject . "\n" . substr($user_message, 0, 158), "From: noreply@networkssms.com\nX-PHP-Script: 1");
//mail("galtech.staffs@gmail.com", $user_subject, $user_message ,"From: noreply@networkssms.com\nX-PHP-Script: 1");
}
?>
我的帐户中没有收到任何邮件。如果我将其作为没有 html 内容的普通邮件或简单邮件提供,则它可以正常工作,但不适用于 html 内容。