需要帮助来解决我的php邮件功能查询

时间:2017-12-13 09:25:00

标签: php email

我对我的电子邮件功能有疑问, 我正在制作一个小组,我们可以通过输入他的电子邮件将旅行套餐的详细信息和行程直接发送给客户。

我真正的问题是,我的一些旅游套餐已成功发送到客户的电子邮件地址,而一些旅游套餐在发送时给我错误。

这是我在发送电子邮件时遇到的以下错误。 以下是我得到的最后一个错误:

Array ( [type] => 8 [message] => Undefined variable: message [file] => /home/jonn5/public_html/webapp/includes/download.php [line] => 68 )

以下是我的邮寄目的代码:

include_once 'db_connect.php';
include_once 'functions.php';
sec_session_start();
$p5 = $_POST['markup'];
$id = $_POST['packid'];


if(isset($_POST['send_email']))
{
    $id = $_POST['packid'];
    if($_POST['client_email']=='' || $_POST['markup']=='')
    {
        $mailmsg = 'Client email or markup missing';
        echo "<script>alert('Client or Markup Missing');</script>";
        echo "<script>this.window.close();</script>";
    }
    else
    {
$mailmsg='';
$to = $_POST['client_email'];
$p5 = $_POST['markup'];
$subject = 'Tour details';
$agent = $_SESSION['username'];
$queryagent= mysqli_query($mysqli,"SELECT * FROM rmt_users where rmt_uname = '$agent'");
while($rsagent=mysqli_fetch_array($queryagent)){
$email = $rsagent['rmt_uemail'];
$imagepath = $rsagent['rmt_ulogo'];
if($imagepath==''){$imagepath='images/logo.png';}
$phone = $rsagent['rmt_uphone'];
}
$result1= mysqli_query($mysqli,"SELECT * FROM rmt_tours where p_id = '$id'");
while($row1 = mysqli_fetch_array($result1))
{
$p1 = $row1['p_2star'];
$p2 = $row1['p_3star'];
$p3 = $row1['p_4star'];
$p4 = $row1['p_5star'];
$markup = '0.'.$p5;
$r1 = $p1*$markup;
$r1 = $p1+$r1;
$r2 = $p2*$markup;
$r2 = $p2+$r2;
$r3 = $p3*$markup;
$r3 = $p3+$r3;
$r4 = $p4*$markup;
$r4 = $p4+$r4;

$message .='
<html>
<head>
<style>
table, td, th {
border: 1px solid #ddd;
text-align: left;
}

table {
border-collapse: collapse;
width: 100%;
}

th, td {
padding: 15px;
}
</style>
</head>
<body>';  ///this is line 68

$message .='
<table>
<tr><td width="10%"></td><td width="30%"></td><td width="60%"></td></tr>
<tr><td colspan="3"><img src="http://agent.routemate.in/'.$imagepath.'" height="25px" width="auto"></td></tr>
<tr><td colspan="3">For Any Query Email us at : <a href="mailto:'.$email.'">'.$email.'</a> or call us on <a href="tel:'.$phone.'">'.$phone.'</a></td></tr>
<tr><td>Package ID</td><td>Package Name</td><td>No of Nights</td></tr>
<tr><td>'.$row1["p_id"].'</td><td>'.nl2br(htmlspecialchars($row1["p_nights"])).'</td><td>'.$row1["p_name"].'</td></tr>
<tr><td>Hotel Category</td><td>Hotel Details</td><td>Package Cost</td></tr>';

$message .='
<tr><td>2 Star</td><td>'.nl2br(htmlspecialchars($row1["p_2star_detail"])).'</td><td>'.round($r1).'</td></tr>';

if($row1['p_3star']!='0')
{
    $message .='
<tr><td>3 Star</td><td>'.nl2br(htmlspecialchars($row1["p_3star_detail"])).'</td><td>'.round($r2).'</td></tr>';
}

if($row1['p_4star']!='0')
{
    $message .='
<tr><td>4 Star</td><td>'.nl2br(htmlspecialchars($row1["p_4star_detail"])).'</td><td>'.round($r3).'</td></tr>';
}

if($row1['p_5star']!='0')
{
    $message .='
<tr><td>5 Star</td><td>'.nl2br(htmlspecialchars($row1["p_5star_detail"])).'</td><td>'.round($r4).'</td></tr>';
}

$message .='<tr><td colspan="3">Destination Details</td></tr>
<tr><td colspan="2">Destination Name</td><td>No of Nights</td></tr>';

$b_destinations = json_decode($row1['p_d1']);
$b_nights = json_decode($row1['p_d1n']);

for($i=0;$i<count($b_destinations[0]);$i++)
{
$message .='<tr><td colspan="2">'.$b_destinations[0][$i].'</td><td>'.$b_nights[0][$i].'</td></tr>';
}

$message .='<tr><td>Day</td><td>Itinerary Title</td><td>Itinerary Details</td></tr>';

$titledata = json_decode($row1['p_it_title'] ) ;
$detaildata = json_decode( $row1['p_it_detail'] );

for($i=0;$i<count($titledata[0]);$i++){
    $c = $i+1;
   $message .='<tr><td>Day : '.$c.'</td><td>'.$titledata[0][$i].'</td><td>'.preg_replace("/[^a-zA-Z0-9\s ]/", "", $detaildata[0][$i]).'</td></tr>';
}


$message .='
<tr><td colspan="3">What You Get</td></tr>
<tr><td colspan="3">'.nl2br(htmlspecialchars($row1["p_inclusion"])).'</td></tr>
<tr><td colspan="3">What Excludes</td></tr>
<tr><td colspan="3">'.nl2br(htmlspecialchars($row1["p_exclusion"])).'</td></tr>
<tr><td colspan="3">Places of Intrest</td></tr>
<tr><td colspan="3">'.nl2br(htmlspecialchars($row1["p_other"])).'</td></tr>';


$message .='<tr>
<td colspan="3"><h4>Note : Above Cost is Excluding 5% GST</h4>
<ul>
<li>This is just a quote, no reservations held yet or booking is not proceed yet.</li>
<li>The rooms & rates are subject to availability at the time of booking / confirmation.</li>
<li>Hotel, Sightseeing, Meals, Transfers rate might change without any prior notice until & unless it been booked/ confirmed from your end.</li>
<li>The change in dates and increase or decrease of number of persons will attract re-quote.</li>
<li>Additional Bank charges will be applicable, if payment is made in foreign currency.</li>
<li>The above cost does not include any kind of surcharge if applicable during the given travel period.</li>
<li>Quotation might change due to currencies ROE fluctuation during confirmation & booking process</li>
<li style="color:red;"><b>Important Note</b></li>
<li style="color:red;">No Refund on unutilized services</li>
<li style="color:red;">Rates are valid for Indian nationals only </li>
</ul>

<h4 style="color:red;">Cancellation Policy</h4>
<ul>
<li>90-29 Days: 10% Of The Total Cost</li>
<li>30- 20 Days: 30% Of The Total Cost</li>
<li>20 – 15 Days: 50% Of The Total Cost</li>
<li>15 – 07 Days: 75% Cancellation Will Apply</li>                        
<li>07 – 00 Days: 100% Cancellation Will Apply</li>
<li>No Refund Either In Part Or In Full Will Be Made For Any Unused Part Of The Services provided in the package</li>
<li>Any Refund shall be claimed with in forty five working days</li>
<li>In case of cancellation of reserved tickets from our end you will be charged three hundred rupees per seat for railway tickets and three hundred and fifty rupees for per seat for airline tickets</li> 
 </ul>
<b>For Any Clarification/ Query feel free to contact us.<br>Assuaring You The Best Of Our Service  At All The Time.</b>
</td></tr>';
}

$message .='</table></body></html>';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$from = $_SESSION['email'];
$from = filter_var($from, FILTER_SANITIZE_EMAIL);

//$from = 'info@routemate.in';

// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();


// Sending email
$success = mail($to, $subject, $message, $headers);
if (!$success) {
    $errorMessage = error_get_last()['message'];
    print_r(error_get_last());
}

}
}

根据错误我在第68行有错误, 但第68行只有这个

$message = '</body>';

为什么会这样?一些包发送成功,而有些包给我这个错误。

此处更新:对于发送时收到错误的邮件,我不知道邮件有什么问题。 对于成功发送的包,他们将被发送到登录代理的电子邮件ID,当时代理已登录,邮件是从代理的电子邮件ID发送的, 最有趣的是给我这个错误的旅行包,我使用我的本地邮件ID发送电子邮件,然后成功提交。 它的大脑堵塞了我。

1 个答案:

答案 0 :(得分:0)

您遇到此错误,因为该行无法访问$ message。因为你在while($row1 = mysqli_fetch_array($result1))这个函数内部声明它并且在该函数之外无法访问,所以在开始时声明$ message。我认为你在顶部宣布$mailmsg='';而忘记使用它而你使用$ message。

include_once 'db_connect.php';
include_once 'functions.php';
sec_session_start();
$p5 = $_POST['markup'];
$id = $_POST['packid'];


if(isset($_POST['send_email']))
{
    $id = $_POST['packid'];
    if($_POST['client_email']=='' || $_POST['markup']=='')
    {
        $mailmsg = 'Client email or markup missing';
        echo "<script>alert('Client or Markup Missing');</script>";
        echo "<script>this.window.close();</script>";
    }
    else
    {
$mailmsg='';
$message='';
$to = $_POST['client_email'];
$p5 = $_POST['markup'];
$subject = 'Tour details';
$agent = $_SESSION['username'];
$queryagent= mysqli_query($mysqli,"SELECT * FROM rmt_users where rmt_uname = '$agent'");
while($rsagent=mysqli_fetch_array($queryagent)){
$email = $rsagent['rmt_uemail'];
$imagepath = $rsagent['rmt_ulogo'];
if($imagepath==''){$imagepath='images/logo.png';}
$phone = $rsagent['rmt_uphone'];
}
$result1= mysqli_query($mysqli,"SELECT * FROM rmt_tours where p_id = '$id'");
while($row1 = mysqli_fetch_array($result1))
{
$p1 = $row1['p_2star'];
$p2 = $row1['p_3star'];
$p3 = $row1['p_4star'];
$p4 = $row1['p_5star'];
$markup = '0.'.$p5;
$r1 = $p1*$markup;
$r1 = $p1+$r1;
$r2 = $p2*$markup;
$r2 = $p2+$r2;
$r3 = $p3*$markup;
$r3 = $p3+$r3;
$r4 = $p4*$markup;
$r4 = $p4+$r4;

$message .='
<html>
<head>
<style>
table, td, th {
border: 1px solid #ddd;
text-align: left;
}

table {
border-collapse: collapse;
width: 100%;
}

th, td {
padding: 15px;
}
</style>
</head>
<body>';  ///this is line 68

$message .='
<table>
<tr><td width="10%"></td><td width="30%"></td><td width="60%"></td></tr>
<tr><td colspan="3"><img src="http://agent.routemate.in/'.$imagepath.'" height="25px" width="auto"></td></tr>
<tr><td colspan="3">For Any Query Email us at : <a href="mailto:'.$email.'">'.$email.'</a> or call us on <a href="tel:'.$phone.'">'.$phone.'</a></td></tr>
<tr><td>Package ID</td><td>Package Name</td><td>No of Nights</td></tr>
<tr><td>'.$row1["p_id"].'</td><td>'.nl2br(htmlspecialchars($row1["p_nights"])).'</td><td>'.$row1["p_name"].'</td></tr>
<tr><td>Hotel Category</td><td>Hotel Details</td><td>Package Cost</td></tr>';

$message .='
<tr><td>2 Star</td><td>'.nl2br(htmlspecialchars($row1["p_2star_detail"])).'</td><td>'.round($r1).'</td></tr>';

if($row1['p_3star']!='0')
{
    $message .='
<tr><td>3 Star</td><td>'.nl2br(htmlspecialchars($row1["p_3star_detail"])).'</td><td>'.round($r2).'</td></tr>';
}

if($row1['p_4star']!='0')
{
    $message .='
<tr><td>4 Star</td><td>'.nl2br(htmlspecialchars($row1["p_4star_detail"])).'</td><td>'.round($r3).'</td></tr>';
}

if($row1['p_5star']!='0')
{
    $message .='
<tr><td>5 Star</td><td>'.nl2br(htmlspecialchars($row1["p_5star_detail"])).'</td><td>'.round($r4).'</td></tr>';
}

$message .='<tr><td colspan="3">Destination Details</td></tr>
<tr><td colspan="2">Destination Name</td><td>No of Nights</td></tr>';

$b_destinations = json_decode($row1['p_d1']);
$b_nights = json_decode($row1['p_d1n']);

for($i=0;$i<count($b_destinations[0]);$i++)
{
$message .='<tr><td colspan="2">'.$b_destinations[0][$i].'</td><td>'.$b_nights[0][$i].'</td></tr>';
}

$message .='<tr><td>Day</td><td>Itinerary Title</td><td>Itinerary Details</td></tr>';

$titledata = json_decode($row1['p_it_title'] ) ;
$detaildata = json_decode( $row1['p_it_detail'] );

for($i=0;$i<count($titledata[0]);$i++){
    $c = $i+1;
   $message .='<tr><td>Day : '.$c.'</td><td>'.$titledata[0][$i].'</td><td>'.preg_replace("/[^a-zA-Z0-9\s ]/", "", $detaildata[0][$i]).'</td></tr>';
}


$message .='
<tr><td colspan="3">What You Get</td></tr>
<tr><td colspan="3">'.nl2br(htmlspecialchars($row1["p_inclusion"])).'</td></tr>
<tr><td colspan="3">What Excludes</td></tr>
<tr><td colspan="3">'.nl2br(htmlspecialchars($row1["p_exclusion"])).'</td></tr>
<tr><td colspan="3">Places of Intrest</td></tr>
<tr><td colspan="3">'.nl2br(htmlspecialchars($row1["p_other"])).'</td></tr>';


$message .='<tr>
<td colspan="3"><h4>Note : Above Cost is Excluding 5% GST</h4>
<ul>
<li>This is just a quote, no reservations held yet or booking is not proceed yet.</li>
<li>The rooms & rates are subject to availability at the time of booking / confirmation.</li>
<li>Hotel, Sightseeing, Meals, Transfers rate might change without any prior notice until & unless it been booked/ confirmed from your end.</li>
<li>The change in dates and increase or decrease of number of persons will attract re-quote.</li>
<li>Additional Bank charges will be applicable, if payment is made in foreign currency.</li>
<li>The above cost does not include any kind of surcharge if applicable during the given travel period.</li>
<li>Quotation might change due to currencies ROE fluctuation during confirmation & booking process</li>
<li style="color:red;"><b>Important Note</b></li>
<li style="color:red;">No Refund on unutilized services</li>
<li style="color:red;">Rates are valid for Indian nationals only </li>
</ul>

<h4 style="color:red;">Cancellation Policy</h4>
<ul>
<li>90-29 Days: 10% Of The Total Cost</li>
<li>30- 20 Days: 30% Of The Total Cost</li>
<li>20 – 15 Days: 50% Of The Total Cost</li>
<li>15 – 07 Days: 75% Cancellation Will Apply</li>                        
<li>07 – 00 Days: 100% Cancellation Will Apply</li>
<li>No Refund Either In Part Or In Full Will Be Made For Any Unused Part Of The Services provided in the package</li>
<li>Any Refund shall be claimed with in forty five working days</li>
<li>In case of cancellation of reserved tickets from our end you will be charged three hundred rupees per seat for railway tickets and three hundred and fifty rupees for per seat for airline tickets</li> 
 </ul>
<b>For Any Clarification/ Query feel free to contact us.<br>Assuaring You The Best Of Our Service  At All The Time.</b>
</td></tr>';
}

$message .='</table></body></html>';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$from = $_SESSION['email'];
$from = filter_var($from, FILTER_SANITIZE_EMAIL);

//$from = 'info@routemate.in';

// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();


// Sending email
$success = mail($to, $subject, $message, $headers);
if (!$success) {
    $errorMessage = error_get_last()['message'];
    print_r(error_get_last());
}

}
}

我认为这应该有用。