2

经过一场战斗,获得梨的正确位置后,我的代码不会产生任何错误。但是它不会发送电子邮件。电子邮件正文是从一个表单生成的,该表单首先将数据输入 mysql 数据库,然后将相同的数据通过电子邮件发送给一个人,然后该人将这些数据用于任何用途。我已经在这个论坛和其他(这是最好的)上阅读了大量的问题和答案,并且我编写的大部分代码都受到了这个论坛的启发。gmail账号有效,密码正确。任何帮助或建议将不胜感激。

pear 和 pear mail 安装在服务器上并且似乎正在工作(至少没有产生任何错误)这是我的代码:

   //Email process code


   ini_set('display_errors','on');
   error_reporting(E_ALL);
   /*
   require_once 'System.php';
  if(class_exists('System')===true) {
  echo 'PEAR is installed!';
  } else {
  echo 'PEAR is not installed :(';
   }
  */

  set_include_path('/home/surfcup/php/');
  require_once "Mail.php";


  $from = "<me@gmail.com>";
  $ToEmail = "<new@apdapalabs.com>"; 


  $EmailSubject = 'Hotel Registration Form'; 

  $host ="ssl://smtp.gmail.com";
  $port ="465";
  $username = "myAccount@gmail.com";
  $password =   "password";


  $headers = array ('From' => $from, 'To'=> $ToEmail, 'Subject'=> $EmailSubject);

  $smtp = Mail::factory('smtp',
    array ('host'=> $host,
           'port'=> $port,
           'auth'=> true,
           'username'=> $username,
           'password'=> $password));

  $MESSAGE_BODY = "Event: ".$Event."\n"; 
  $MESSAGE_BODY .= "Name: ".$realname."\n"; 
  $MESSAGE_BODY .= "Age Group: ".$Age."\n"; 
  $MESSAGE_BODY .= "Sex: ".$Sex."\n"; 
  $MESSAGE_BODY .= "Contact Name: ".$Contact_Name."\n"; 
  $MESSAGE_BODY .= "Contact Email: ".$Contact_Email."\n"; 
  $MESSAGE_BODY .= "Phone: ".$Phone."\n"; 
  $MESSAGE_BODY .= "Hotel Name: ".$Hotel_Name."\n"; 
  $MESSAGE_BODY .= "No Rooms: ".$No_Rooms."\n"; 
  $MESSAGE_BODY .= "Rate: ".$Rate."\n"; 
  $MESSAGE_BODY .= "Check In Date: ".$Check_In."\n"; 
  $MESSAGE_BODY .= "Check Out Date: ".$Check_Out."\n"; 
  $MESSAGE_BODY .= "Additional Info: ".$Add_Info."\n"; 



  $mail = $smtp->send($ToEmail, $headers, $MESSAGE_BODY);


        if (PEAR::isError($mail)){
            echo("<p>" . $mail->getMessage . "</p>");
            echo("\n");
            echo("<p>" . $mail->getDebugInfo . "</p>");

        }
4

1 回答 1

1

我看到的关于通过 GMAIL 发送的大多数错误是您自己的服务器上未启用 OpenSSL。检查您的 php.ini 中是否启用了扩展

(另外,如果失败,您能否错误检查“smtp”。)

于 2012-05-23T00:38:36.093 回答