简体   繁体   中英

PHP Not sent automatic email on remote server

I wrote codes that should send auto email using PEAR. every thing is OK on my local MAC OS system but not working on windows based remote server. here is my codes:

<?php require_once('../config/connection.php'); 
include_once("Mail.php"); 
$id=$_GET['id'];
if(isset($_POST['update-visa-status-btn'])){
    $status=$_POST['status'];
mysqli_query($con,"UPDATE `visa` SET `status`='$status' WHERE `id`='$id'");
$visa=mysqli_query($con,"SELECT * FROM `visa` WHERE `id`='$id'");
$row_visa=mysqli_fetch_assoc($visa);
$user_id=$row_visa['userid'];
$user_info=mysqli_query($con,"SELECT * FROM `user` WHERE `id`='$user_id'");
$row_user_info=mysqli_fetch_assoc($user_info);
$From = "..."; 
$To="...";
$Subject = "..."; 
$Message = '
<html>
<head>
</head>
<body>
<!-- SOME HTML CODES THAT MAKES HTML EMAIL BODY -->
</body>
</html>'; 
$Host = "..."; 
$Username = "..."; 
$Password = "..."; 
$content_type="text/html"; 
$Headers = array ('From' => $From, 'To' => $To, 'Subject' => $Subject, 'content-type' => $content_type); 
$SMTP = Mail::factory('smtp', array ('host' => $Host, 'auth' => true, 
'username' => $Username, 'password' => $Password)); 
$mail = $SMTP->send($To, $Headers, $Message); 
if (PEAR::isError($mail)){ 
echo($mail->getMessage()); 
} else { 
echo("Email Message sent!"); 
}}
?>

On remote server none of messages success or error not shown & no email sent but on local, every thing works like a charm.Thank you for your help.

First please escape the GET and POST variables:

$escaped_string = mysqli_real_escape_string($connection, $string)

Secondly: For Email sending purpose use PHPMailer a free repository to send emails. You can get this from github: https://github.com/PHPMailer/PHPMailer There you will also find the Process you need to follow to get your emails sent.

I'm using this PHPMailer for ages now. It is easy, robust and hardly fails on me.

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