Jump to content
WAMFT1

Sending Email Issues

Recommended Posts

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 by requinix

Share this post


Link to post
Share on other sites

Well, based on the syntax highlighting in your post, it appears you're missing a quote somewhere to end a string.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

define: "it crashes"? does the server fall out of the rack and crash to the floor or what?  :happy-04:  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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.