我需要什么:
当用户点击带有html内容的按钮邮件时,应该收到食谱。
我的问题:
这是我的代码mail.php
require 'PHPMailerAutoload.php';
$message = '
<html>
<head>
<title>ES Html Report</title>
</head>
<body>
<table>
<tr>
<th>Project Name</th>
<th>TODo</th>
<th>Priority</th>
<th>Due on</th>
<th>Assignee</th>
<th>Created</th>
<th>Updated</th>
<th>Completed</th>
<th>Assignee Status</th>
<th>Status</th>
</tr>
<tr>
<td>aaaa</td>
</tr>
<tr>
<td>Sally</td
</tr>
<td>1</td>
</tr>
<tr>
<td>ankit</td>
</tr>
<tr>
<td>1-09-89</td>
</tr>
<tr>
<td>1-08-77</td>
</tr>
<tr>
<td>177th</td>
</tr>
<tr>
<td>ok</td>
</tr>
<tr>
<td>gg</td>
</tr>
<tr>
<td>1710th</td>
</tr>
</table>
</body>
</html>
';
$mail = new PHPMailer();
$mail->isSendmail();
$mail->setFrom('af15@gmail.com', 'First Last');
//$mail->addReplyTo('af@ankrus.com', 'First Last');
$mail->addAddress('aef@anus.com', 'John Doe');
$mail->Subject = $subject ;
$msg = 'my html and php code that format the mail';
$body= preg_replace('/\[\]/','',$msg);
$mail->msgHTML($body);
$mail->msgHTML($message)
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
*问题只有邮寄文本时才会出现问题但是没有使用Phpmailer库邮寄html内容。
*在这段代码中我发送文本发送没有错误,但发送html
有问题$msg = 'my html and php code that format the mail';
$body= preg_replace('/\[\]/','',$msg);
$mail->msgHTML($body);
答案 0 :(得分:-2)
$data='<table border=1px solid>'.'<tr>'.'<td>'.'EMPLOYEE NAME'.'<td>'.'TO DATE'.'</td>'.'<td>'.'FROM DATE'.'</td>'.'<td>'.'LEAVETYPE'.'</td>'.'<td>'.'REASON'.'</td>.';
You Write Html Tags In Adding Way.
if you have any doubt ask me.
my Full code is
$mail->MsgHTML("$data");
include "classes/class.phpmailer.php"; // include the class name
$pa="SELECT DISTINCT PARENT_ID FROM ORGCHART";
$pa2=odbc_exec($conn,$pa);
while(odbc_fetch_row($pa2))
{
$parentid=odbc_result($pa2,"PARENT_ID");
$c=better_odbc_num_rows($conn,$parent);
$leave2=odbc_exec($conn,$parent);
$lv='';
$cv='';
$ov='';
$hr="<table border=1px solid>"."<tr>"."<td>"."EMPLOYEE NAME"."<td>"."TO DATE"."</td>"."<td>"."FROM DATE"."</td>"."<td>"."LEAVETYPE"."</td>"."<td>"."REASON"."</td>.";
while(odbc_fetch_row($leave2))
{
$todate=odbc_result($leave2,"TODATE");
$todate=date('d-M-Y',strtotime($todate));
$fromdate=odbc_result($leave2,"FROMDATE");
$fromdate=date('d-M-Y',strtotime($fromdate));
$lv.="<tr>"."<td>".odbc_result($leave2,"FIRSTNAME").
"</td>"."<td>".$todate."</td>"."<td>".$fromdate."</td>"."<td>".
odbc_result($leave2,"LEAVETYPE")."</td>".
"<td>".odbc_result($leave2,"REASON")."</td>"."</tr>"."</br>";
}
if($c>0)
{
$ema="SELECT EMAIL FROM EMPLOYEE WHERE EMP_ID=$parentid";
$ema=odbc_exec($conn,"$ema");
$email=odbc_result($ema,"EMAIL");
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for hotMail
//$mail->SMTPSecure = 'ssl';// secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587
$mail->STARTTLS = 1;
$mail->IsHTML(true);
$mail->Username = "";
$mail->Password = "";
$mail->SetFrom("");
$mail->Subject = "eLeave";
$mail->Body = "eLeave Tracking System";
$mail->MsgHTML("$hr.$lv");
$mail->AddAddress("");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
}
}
?>