简体   繁体   中英

Php SMTP mail Issue

I got a project which I need to create a personal web site but I can not send e mail via contact form. Could you pls assist me what do I need to do in order to fix it.

I have added class.phpmailer.php and class.smtp.php. Here is php code;

<? php

include 'class.phpmailer.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; //  or  587
$mail->IsHTML(true);
 $mail->Username = "behzatdeniz82@gmail.com";
$mail->Password = "myseccretpassword"; //Don't reveal password with others
$mail->SetFrom("behzatdeniz82@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("behzatdeniz99@gmail.com");
 if(!$mail->Send())
 {
 echo "Mailer Error: " . $mail->ErrorInfo;
 }
 else
 {
 echo "Message has been sent";
 }
 ?> 

After I change the php code as above, now I begin to receive this error. Can anyone help me how to fix ?

 SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" 
 - did you forget to enable it when you configured PHP? (1702478359) 
 SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: 
 Could not connect to SMTP host. 

It seems like SetFrom method is missing. There are multiple versions of PHPMailer available. Download PHPMailer 5.1 which contains a setFrom method:

  public function SetFrom($address, $name = '',$auto=1) {   

Just Try.

只是一个小错误,可能是解决方案:我的名字后,$ mail-> SetFrom($ mail-> Username,'My Name)之后缺少'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM