-
-
require_once(dirname(__FILE__)."/../PHPMailer/class.phpmailer.php");
//Contains class.phpmailer.php
- /**
- * @param string $send_to_mail target email
- * @param stinrg $subject subject
- * @param string $body email content
- * @param string $extra_hdrs additional information
- * @param string $username recipient
- * @param string $replyname reply person
- * @param string $replymail reply address
- * @return array(bealoon,string) The returned array includes two elements, bealoon indicates whether it is successful, and string is the prompt message
- */
- function SendMail($send_to_mail,$subject,$body,$extra_hdrs,$username,$replyname="reply",$replymail="reply@reply.com" ){
- $mail=new PHPMailer();
- $mail->IsSMTP(); //Email sending method
- $mail->Host="smtp.host.com"; //SMTP server host address
- $ mail->SMTPAuth=true; //Whether it is a trusted SMTP
- $mail->Username="reply@reply.com"; //SMTP username Note: Ordinary email authentication does not require adding @domain name
- $mail ->Password="******"; //SMTP user password
- $mail->From="send@send.com"; //Sender's email address
- $mail->FromName= "send"; //Sender
- $mail->CharSet="GB2312"; //Specify character set
- $mail->Encoding="base64";
- $mail->AddAddress($send_to_mail,$ username); //Add the sending destination address
- $mail->AddReplyTo($replymail,$replyname); //Add the reply address
- $mail->IsHTML(true); //The email type is HTML format
- $mail ->Subject=$subject; //Email subject
- //Email content
- $mail->Body="
- ".$body."
-
- ";
- $mail->AltBody="text/html"; //Content text format
- if (@!$mail->Send()) {
- $results =array("result"=>false,"message"=>$mail->ErrorInfo);
- return $results;
- }else{
- $results = array("result"=>true,"message "=>"The email has been sent to {$send_to_mail}! ");
- return $results;
- }
- }
$send_mail=SendMail($to,$subject,$content,$headers,$name);
- if($send_mail[" result"]){
- echo $send_mail["message"];
- }else{
- echo $send_mail["message"];
- }
- exit();
- ?>
-
Copy Code
Example 2:
-
-
- include ('class/class.phpmailer.php');
$config = array(
- 'host'=> ;'smtp.163.com',
- 'port'=>'25',
- 'user'=>'***',
- 'passwd'=>'****',
- 'from '=>'juva_zz@163.com',
- 'fromname'=>'Zhengzhou',
);
- $subject = 'this is a test mail';
- $body = '
Test content | This is the content | ';
- $address='379018082@qq.com';
- $username='me';
$mail = new PHPMailer() ;
- $mail->CharSet = 'gb2312';
- $mail->IsSMTP();
- $mail->Host = $config['host'];
- $mail->Port = $config[ 'port'];
$mail->From = $config['from'];
- $mail->FromName = $config['fromname'];
- $mail- >SMTPAuth = true;
$mail->Username = $config['user'];
- $mail->Password = $config['passwd']; p>
$mail->Subject=$subject;
- $mail->AltBody="text/html";
- $mail->MsgHTML($body);
- < ;p>$mail->AddAddress($address,$username);
if(!$mail->Send())
- {
- echo "Mail Error :".$ mail->ErrorInfo;
- }else
- {
- echo "Congratulations on successful sending! ";
- }
-
Copy code
|