1

I am using phpMailer i do not know whats wrong with my code, it return fails after execution? my function which call the phpmailer.php page and takes parameters:

function sendEmail($to,$from,$sender_name="",$subject,$body,$attachement_path){ 
  require("PHPMailer/class.phpmailer.php");
  $mail = new PHPMailer(); 
  $host="mail.mysite.com";
  $userName="info";
  $password="password!";
  $mail->IsSMTP();                                      // set mailer to use SMTP i.e. smtp1.example.com;smtp2.example.com
  $mail->Host = $host;  // specify main and backup server
  $mail->SMTPAuth = true;     // turn on SMTP authentication
  $mail->Username = $userName;  // SMTP username i.e email id of an email address
  $mail->Password = $password; // SMTP password for the specified email address         
  $mail->From = $from;
  $mail->FromName = $sender_name;
  $mail->AddAddress($to);   //mail,name
  $mail->AddAddress("myBCCMailAddress@gmail.com");                  // name is optional
  $mail->AddReplyTo($to);//to, name         
  $mail->WordWrap = 50; 
  $mail->AddAttachment($attachement_path);
  $mail->IsHTML(true);                                 // set email format to HTML
  $mail->Subject = $subject;
  $mail->Body    = $body;
  //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";      
  if(!$mail->Send())
  {
     return false;
      }
  else{
      return true;
      }
  }

Here is the calling method of my above function:

if(sendEmail($to,"info@mysite.com","My Company Name",$subject,$body,$path)){
              echo 'mail sent';
              }
           else{
               echo('mail failed to send '.$to);
               }
4

1 回答 1

0

这是我使用的脚本。

        // phpmailer is required earlier
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->isHtml(true);
        $mail->AddAddress($customer_email);

        $mail->From = 'billing@example.com';
        $mail->FromName = 'MyName';
        $mail->Sender = 'mailman@example.com';

        $mail->AddBcc('accounting@example.com);
        $mail->Subject = 'Invoince;

        $mail->Body = 'Some exiting text explaining the customer about his invoice';
        $mail->AddAttachment('/var/invoices/'.$invoce_nr.'.pdf', 'Faktura.pdf');
        $mail->Body = iconv("UTF-8", "ISO-8859-1",$mail->Body);

        if($mail->send()){
            return true;
        } else {
            return false;
        }

还要确保您可以发送常规电子邮件,然后确保您尝试发送的文件是可读的。

于 2012-11-13T17:31:06.573 回答