Jump to content

phpMailer suddenly stopped sending mail :(


Go to solution Solved by lovephp,

Recommended Posts

i have had mails being sent ok and i tested server is still sending mail but my scripts stopped sending mail be it with phpmailer of just general test, im talking only withing the script where config file is included

ob_start();session_start();error_reporting(0);//set timezone$timezone = "Asia/Manila"; if(function_exists('date_default_timezone_set')){     date_default_timezone_set($timezone); }function validDate($dstring){    return (bool)strtotime($dstring);}//database credentialsdefine('DBHOST','localhost');define('DBUSER','root');define('DBPASS','');define('DBNAME','123');//application addressdefine('DIR','http://localhost/test/');define('SITEURL','www.site.com');define('SITEEMAIL','noreply@site.com');$per_page = 10;try {	//create PDO connection	$db = new PDO("mysql:host=".DBHOST.";dbname=".DBNAME, DBUSER, DBPASS);	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    	$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC); 	} catch(PDOException $e) {	//show error    echo '
'.$e->getMessage().'';    exit;}include('classes/phpmailer/mail.php');

have not made any changes to my registration page except for in config.php i added these 2 line$db->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC); does this has anything to do with sending email?here is how i send the mail

$to = $_POST['email'];			$subject = "Registration Confirmation";			$body = "
Dear ".$_POST['username'].",
Thank you for registering at ".SITEURL.".			
To activate your account, please click on this link: ".DIR."activate.php?x=$id&y=$activasion			
Regards,
Admin
".SITEURL."
tel:1234567890";			$mail = new Mail();			$mail->setFrom(SITEEMAIL);			$mail->addAddress($to);			$mail->subject($subject);			$mail->body($body);			$mail->send();

and i also tried sending mail like

$to = $_POST['email'];		   $subject = "Registration Confirmation"; 		   $headers = "From: www.site.com \r\n";		   $headers .= 'MIME-Version: 1.0' . "\n"; 		   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  		   $headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n";		   'X-Mailer: PHP/' . phpversion();              $message = "
Dear ".$_POST['username'].",
Thank you for registering at ".SITEURL.".			
To activate your account, please click on this link: ".DIR."activate.php?x=$id&y=$activasion			
Regards,
Admin
".SITEURL."
tel:1234567890\n";             mail($to, $subject, $message, $headers);

both not sending emails from the script anymore

Link to comment
https://forums.phpfreaks.com/topic/301505-phpmailer-suddenly-stopped-sending-mail/
Share on other sites

have not made any changes to my registration page except for in config.php i added these 2 line $db->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC); does this has anything to do with sending email?

 

 

if your code isn't using the database, those lines of code would have no affect on what your code does. however, if you are using a database, there are some inconsistencies between running an emulated prepared query and running a real prepared query (thanks php) that could be throwing an error, and depending on how you are handling any thrown errors, combined with the error_reporting level you have set in your code, could result in your code halting without showing any error information.

 

don't set error_reporting to zero. it should ALWAYS be set to E_ALL. when debugging problems, you should display errors (set display_errors to ON), otherwise they should be logged (set display_errors to OFF and set log_errors to ON). also, don't use output buffering statements in your code unless you ARE buffering output. they hide messages from your code and php error messages.

Edited by mac_gyver
  • Like 1

this is how the script looks

 

if(isset($_POST['submit'])){

if($_POST['username'] == ''){
        $error[] = 'Username is required.';
    }

if(!isset($error))
$hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYPT);
try {

$stmt = $db->prepare('INSERT INTO members (username,password) VALUES (:username, :password)');
            $stmt->execute(array(
                ':username' => $_POST['username'],
                ':password' => $hashedpassword
            ));
 
echo $to = $_POST['email'];
            $subject = "Registration Confirmation";
            $body = "<p>Dear ".$_POST['username'].",</p><p>Thank you for registering at ".SITEURL.".</p>
            <p>To activate your account, please click on this link: <a href='".DIR."activate.php?x=$id&y=$activate'>".DIR."activate.php?x=$id&y=$activasion</a></p>
            <p>Regards,<br/>Admin<br/>".SITEURL."<br/>+91 <a href='tel:8486764090'>8486764090</a></p>";

            $mail = new Mail();
            $mail->setFrom(SITEEMAIL);
            $mail->addAddress($to);
            $mail->subject($subject);
            $mail->body($body);
            $mail->send();
            
            } catch(PDOException $e) {
            $error[] = $e->getMessage();
        }            
    }
}  

 

what more error can i check for?

Edited by lovephp
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.