Мой последний рабочий код:
function Redirect_to($New_Location){
header("Location:" . $New_Location);
exit;
}
if(isset($_POST['Submitenq'])){
require('phpmailer/PHPMailerAutoload.php');
define ('GUSER','courses@cadcentreju.org');
define ('GPWD','mailpass');
$recever1 = 'courses@cadcentreju.org';
$enq_name = $_POST["enq_name"];
$enq_email = $_POST["enq_email"];
$enq_phone = $_POST["enq_phone"];
$enq_message = $_POST["enq_message"];
date_default_timezone_set("Asia/Kolkata");
$CurrentTime = time();
$DateTime = strftime("%B-%d-%Y %H:%M:%S",$CurrentTime);
if(empty($enq_name) || empty($enq_email) || empty($enq_phone) || empty($enq_message)){
Redirect_to("index.php?error=1");
}else{
$mail = new PHPMailer(true);
try{
$mail->IsSMTP();
$mail->Mailer = "smtp";
// $mail->SMTPDebug = 2;
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = "none";
$mail->Port = 25;
$mail->Host = "mail.supremecluster.com";
// $mail->CharSet = "UTF-8";
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->isHTML(true);
$mail->setFrom($enq_email,$enq_name);
$mail->From = GUSER;
$mail->FromName = $enq_name;
$mail->addAddress($recever1);
$mail->Subject = 'Enquiry Mail from - '. $enq_name;
$mail->Body = '<table class="table" cellspacing="0">
<thead>
<tr>
<th colspan="2">Enquiry Mail from - '. $enq_name .'</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">'. '<p>Dear Sir / Madam, I have some enquiries. My Details are as follows :</p></br>' .'</td>
</tr>
<tr>
<td>Email:</td>
<td>'. $enq_email .'</td>
</tr>
<tr>
<td>Phone No:</td>
<td>'. $enq_phone .'</td>
</tr>
<tr>
<td>Message:</td>
<td>'. $enq_message .'</td>
</tr>
<tr>
<td>Date and TIME of Enquery:</td>
<td>'. $DateTime .'</td>
</tr>
</tbody>
</table>';
$mail->send();
$success_msg = "Your Message Sent Successfully: ";
}catch(phpmailerException $e){
echo $e->errorMessage();
}catch(Exception $e){
echo $e->getMessage();
}
Я решил отправлять почту с моего собственного сервера вместо сервера Gmail:
Итак, я изменил:
$mail->SMTPSecure = "ssl";
на
$mail->SMTPSecure = "none";
Самое важное, помнить, что:
$mail->Username = GUSER;
И
$mail->From = GUSER;
ДОЛЖЕН БЫТЬ ТО ЖЕ
AND
Кроме того, мы должны передать конструктору значение true:
$mail = new PHPMailer(true)
// Аргумент true в конструкторе включает исключения