lovephp Posted July 18, 2016 Share Posted July 18, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/301505-phpmailer-suddenly-stopped-sending-mail/ Share on other sites More sharing options...
mac_gyver Posted July 18, 2016 Share Posted July 18, 2016 (edited) 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 July 18, 2016 by mac_gyver 1 Quote Link to comment https://forums.phpfreaks.com/topic/301505-phpmailer-suddenly-stopped-sending-mail/#findComment-1534622 Share on other sites More sharing options...
lovephp Posted July 18, 2016 Author Share Posted July 18, 2016 this is just so strange i tried just the registration in a sub folder and the scripts works fine but not on the main site im developing and i get no error which is being printet Quote Link to comment https://forums.phpfreaks.com/topic/301505-phpmailer-suddenly-stopped-sending-mail/#findComment-1534623 Share on other sites More sharing options...
lovephp Posted July 18, 2016 Author Share Posted July 18, 2016 (edited) 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 July 18, 2016 by lovephp Quote Link to comment https://forums.phpfreaks.com/topic/301505-phpmailer-suddenly-stopped-sending-mail/#findComment-1534624 Share on other sites More sharing options...
Solution lovephp Posted July 19, 2016 Author Solution Share Posted July 19, 2016 this is sorted after i set domain name in the phpmailer mail.php script i changed the default noreply@domain.com to mine and now it started sending mails real fast Quote Link to comment https://forums.phpfreaks.com/topic/301505-phpmailer-suddenly-stopped-sending-mail/#findComment-1534667 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.