email via phpmailer

5089 ワード

class.phpmailer.php
class.smtp.php
mail.php

<?php

	require("./class.phpmailer.php");

	function SmtpMail($send_to_mail,$subject,$body,$extra_hdrs,$username){

		$mail=new PHPMailer();
		$mail->IsSMTP();
		$mail->Host="mail.xxx.net";
		$mail->SMTPAuth=false;
		$mail->Username="";
		$mail->Password="";
		$mail->From="";
		$mail->FromName="xxx Mailer";
		$mail->CharSet="utf-8";
		$mail->AddAddress($send_to_mail,"$username");
		$mail->AddReplyTo("xxx Mailer","no-reply");
		$mail->IsHTML(true);
		$mail->Subject=$subject;

		if ($body==''){
			$mail->Body="";
		} else {
			$mail->Body="<html><head>
					 <meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>
					 <body>".$body."
					 </body>
					 </html>";
		}

		$mail->AltBody="text/html";
		if (@ !$mail->Send()) {
			$results=array("result"=>false,"message"=>$mail->ErrorInfo);
			return $results;
		}else{
			$results = array("result"=>true,"message"=>"{$send_to_mail} was sent out.");
			return $results;
		}
	}

    $reservation['date']       = $_POST['date'];

    $reservation['time']       = $_POST['time'];

    $reservation['number']     = $_POST['number'];

    $reservation['name']       = $_POST['name'];
    $reservation['phone']      = $_POST['phone'];
    $reservation['email']      = $_POST['email'];
    $reservation['made']       = $_POST['made'];
    $reservation['not_made']   = $_POST['not_made'];
    $reservation['info']       = $_POST['info'];

    $th['date']       = 'Date';
    $th['time']       = 'Time';
    $th['number']     = 'Number of People';
    $th['name']       = 'Name';
    $th['phone']      = 'Phone Number';
    $th['email']      = 'Email Address';
    $th['made']       = 'Preferred contact method<br />if Reservation made';
    $th['not_made']   = 'Preferred contact method if Reservation<br />NOT available at requested Date / Time';
    $th['info']       = 'Further Infomation';

	$table_tr = '';
	foreach($reservation as $k=>$v) {
		$table_tr .= '<tr>';
		$table_tr .= '<th align="left">'.$th[$k].'</th><td>'.htmlspecialchars(strip_tags($v)).'</td>';
		$table_tr .= '</tr>';
	}
	$subject = "New Reservation";
	$body    = "<h2>$subject</h2><table border=1>$table_tr</table>";

	$send_mail=SmtpMail('[email protected]',$subject,$body,'','');


	if($send_mail["result"]){
		$direct = 'thank-you';
	}else{
		$direct = 'sorry';
	}

	echo '<script type="text/javascript">location="processing.php?r='.$direct.'";</script>';

processing.php

<?php
	$title['thank-you'] = 'Thank you';
	$title['sorry'] = 'Sorry';
	$content['thank-you'] = 'Thank you for submitting a Reservation request. xxx will personally contact you ASAP to confirm your Reservation.</p>
							<p>We look forward to seeing you at xxx.';
	$content['sorry'] = 'Sorry, there is something wrong with the processing, please try it later or phone us on xxx.';
?>
					<h1><?php echo $title[$_GET['r']];?></h1><br /><br />

					<p><?php echo $content[$_GET['r']];?></p>


e.g. 163 mail

		$mail=new PHPMailer();
		$mail->IsSMTP();
		$mail->Host="smtp.163.com";
		$mail->SMTPAuth=true;
		$mail->Username="xxx";
		$mail->Password="xxx";
		$mail->From="[email protected]";
		$mail->FromName="xxx Mailer";
		$mail->CharSet="utf-8";
		$mail->AddAddress($send_to_mail,"$username");
		$mail->AddReplyTo("[email protected]","no-reply");
		$mail->IsHTML(true);
		$mail->Subject=$subject;