WAMFT1 Posted September 29, 2016 Share Posted September 29, 2016 (edited) Hi All Another problem I have had since we change web hosts is that we cannot sent through phpmail any more. I have tried to update it to send through SMTP. The page works without the email sending section but with it included it crashes. I cannot see what the problems is but I do not have much experience. Any help is appreciated. <head>... <?php require("../edb.php"); $id =$_REQUEST['id']; $result = mysql_query("SELECT * FROM eusers WHERE id = '$id'"); $test = mysql_fetch_array($result); if (!$result) { die("Error: Data not found.."); } $FirstName=$test['FirstName']; $LastName=$test['LastName']; $Email=$test['Email']; $ActivateCode=$test['ActivateCode']; $Active=$test['Active']; $SecurityCode=$test['SecurityCode']; $Username=$test['Username']; if(isset($_POST['submit'])) { $FirstName_save=$_POST['FirstName']; $LastName_save=$_POST['LastName']; $Active_save=$_POST['Active']; $Email_save=$_POST['Email']; $ActivateCode_save=$_POST['ActivateCode']; $SecurityCode_save=$_POST['SecurityCode']; mysql_query("UPDATE eusers SET Active ='0', Password ='', ActivateCode ='$ActivateCode_save', Notes ='$Notes_save', SecurityCode ='' WHERE id ='$id'") or die(mysql_error("Record did not save")); //EMAIL $smtp_host = "smtp.office365.com"; $smtp_username = "XXXXXXXX"; $smtp_password = "XXXXXXXX"; $smtp_port = "587"; $to = "$FirstName $LastName <$Email> \r\n"; $email_cc = "XXXXXXXX, XXXXXXXX\r\n"; $email_from = "XXXXXXXX <XXXXXXXX> \r\n"; //$headers .= 'MIME-Version: 1.0' . "\r\n"; //$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $email_subject = "XXXXXXXX - Password Reset \r\n"; $email_message = "Hi $FirstName,<br/><br/> Your XXXXXXXX login has been reset as requested.<br/><br/> A link to the login activation page is below. All you need is a preferred password and a Security Code (anything you like) to activate your login.<br/><br/> Remember your Security Code as you will need this to change your password at a later stage. All user names and passwords are case sensitive.<br/><br/> If you have any problems or would like to discuss the XXXXXXXX please feel free to contact me on XXXXXXXX.<br/><br/> Click your Personalised Activation link to setup your login:<a href='http://www.XXXXXXXX/XXXXXXXX/login_activate.php?id=$id&ActivateCode=$ActivateCode_save'> Activate Here</a><br/><br/> For Future Reference the website details are as follows:<br/> XXXXXXXX: <a href='http://www.XXXXXXXX/XXXXXXXX'>http://www.XXXXXXXX/XXXXXXXX</a><br/> Username: $Username<br/>Registered Email: $Email<br/><br/> There's some stuff removed from here that I didn't want to share, but I also didn't fix the syntax error that removing the line caused so requinix is doing it for me"; $headers = array ('From' => $email_from, 'To' => $to, 'CC' => $email_cc, 'Subject' => $email_subject, 'Reply-To' => $smtp_username); $smtp = Mail::factory('smtp', array ('host' => $smtp_host, 'port' => $smtp_port, 'auth' => true, 'username' => $smtp_username, 'password' => $smtp_password)); $mail = $smtp->send($to, $headers, $email_message); //END EMAIL echo "Saved!"; echo "Email Sent!"; printf("<script>location.href='http://www.XXXXXXXX/XXXXXXXX/admin/index_users.php'</script>"); } ...</head> Edited September 29, 2016 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/ Share on other sites More sharing options...
requinix Posted September 29, 2016 Share Posted September 29, 2016 Well, based on the syntax highlighting in your post, it appears you're missing a quote somewhere to end a string. Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/#findComment-1537896 Share on other sites More sharing options...
WAMFT1 Posted September 29, 2016 Author Share Posted September 29, 2016 I check my code, it is just where I removed a line that I did not want to share on here. The string quote is actually closed off on the actual page. Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/#findComment-1537897 Share on other sites More sharing options...
mac_gyver Posted September 29, 2016 Share Posted September 29, 2016 define: "it crashes"? does the server fall out of the rack and crash to the floor or what? keep in mind that we are not sitting right next to you and only see the information you supply in your posts. what exact error or symptom do you get when the code runs that leads you to believe that something crashes? do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would report and display all the errors it detects? btw - the site specific information you had to go through and edit before posting the code should be in defined constants or php variables and be defined in a required file, so that you wouldn't need to alter the code before posting or if you ever reuse the code on a different site, you only need to edit the values in the required file. Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/#findComment-1537898 Share on other sites More sharing options...
WAMFT1 Posted September 29, 2016 Author Share Posted September 29, 2016 Crashes => When I hit submit, the update query part works fine, it seems to stop working around the sending the email part. I just get a blank screen. I don't get the email or the echo "Saved" etc. There seems to be an issue in the actual emailing part which I cannot work out. Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/#findComment-1537903 Share on other sites More sharing options...
mac_gyver Posted September 29, 2016 Share Posted September 29, 2016 you are probably getting a fatal run-time error at either the Mail::factory() or $smtp->send() statement. have you done the following - do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would report and display all the errors it detects? Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/#findComment-1537904 Share on other sites More sharing options...
WAMFT1 Posted September 30, 2016 Author Share Posted September 30, 2016 It looks like the issue is with the Mail::factory Fatal error: Class 'Mail' not found Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/#findComment-1537909 Share on other sites More sharing options...
mac_gyver Posted September 30, 2016 Share Posted September 30, 2016 well, there you go. you would need to find where the Mail class is being defined at and find out why it isn't being defined for the current code. it's not a native php class, so it would be either explicitly required/included or there would be an auto-loader that requires the file containing the class definition. Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/#findComment-1537915 Share on other sites More sharing options...
cyberRobot Posted September 30, 2016 Share Posted September 30, 2016 It looks like the issue is with the Mail::factory Fatal error: Class 'Mail' not found For what it's worth, the first thing that comes up when searching for Mail::factory() is PEAR. Is that what you're using? https://pear.php.net/manual/en/package.mail.mail.factory.php Quote Link to comment https://forums.phpfreaks.com/topic/302255-sending-email-issues/#findComment-1537920 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.