利用PHPMailerAutoLoad发邮件

今天自学php and MySQL web development 4th edition。看到书的109页就开始发邮件啦,教的蛮快的。但是如果在公司,用公司邮件发,用mail() function就太吃力了。关键是我不会配置。找了下,找到了别人在基吧里面的源代码。觉得很方便特拿来用。https://github.com/PHPMailer/PHPMailer


下载下来以后,首先在根目录下建立一个叫lib的文件夹,再把pull下来的东西都放进去。根目录就是你一直用来放index.html,也就是别人能访问到你网站的那个目录。


接下来是那个php的code,抄下来方便以后再抄。

<?php  
   require_once('/lib/PHPMailer/PHPMailerAutoload.php');  
     
  $name = $_POST['customername'];  
  $email = $_POST['customermail'];  
  $feedback = $_POST['contents'];  
    
   $mailcontent ="Customer name: ".$name."<br>".  
                 "Customer email: ".$email."<br>".  
                 "Customer's Comment: ".$feedback."\n";  
    
    
   $headers   = 'Interesting Stuff';  
  
  
   $from_name      = 'Interesting';  
   $from               = 'wpq@ms.com';  
   $mail                = new PHPMailer();  
   $mail->IsSMTP(); // telling the class to use SMTP  
   $mail->Host                    = "smtp.www.com";  
   $mail->Port                    = 587;  
   $mail->SMTPAuth                = true;  
   $mail->Username                = "msou";  
   $mail->Password                = "YourPassWord";  
   $mail->FromName                = $from_name;  
   $mail->From                    = $from;  
   $mail->AddAddress('sender@mo.com','SenderName');  
   $mail->Subject                  =$headers;  
   $mail->addattachment('/images/image.jpg','jpg\'s name');  
   $mail->MsgHTML($mailcontent);  
   $result                        = $mail->Send();   
    
?>  
   
<html>  
<head>  
<title>Bob's Auto Parts - Feedback Submitted</title>  
</head>  
<body>  
<h1>Feedback submitted</h1>  
<p>Your feedback has been sent.</p>  
</body>  
</html>  
不过 php真是用的不多啊。


版权声明:本文为u011410413原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。