Jump to content

Recommended Posts

Hello everybody,

 

I have a problem with the mail() function that pretty much drives me crazy. The weird part about the problem is that the function sometimes does and sometimes doesn't get executed. The problem occurred in many attempts with several email adresses. (Meaning that even on the same email adress it would sometimes work, and sometimes not.

 

Below I included the code, I have a feeling that it's actually not wrong but I wish to check this first before contacting my webhost.

function subscribe($email) {
$email = mysql_real_escape_string($email);
$sql = mysql_query("SELECT email FROM mailinglist WHERE email = '".$email."'") or die("error");
$check = mysql_num_rows($sql);

/* Email */
$subject = 'Twenty Words: Inschrijving.';

$headers = "From: Contact@twentywords.nl\r\n";
$headers .= "Reply-To: Contact@twentywords.nl\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = 'Thank you for subscribing!';
/* End email */

if($check >= 1){
	$result = "You're already subscribed!";
}else if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email)){
	$result = "That's no email adress!";
}else{
	mysql_query("INSERT INTO mailinglist(email, regTime) VALUES('".$email."',NOW())");
	$result = "thanks for subscribing!";
	mail($email, $subject, $message, $headers);
}
return $result;
}	

 

*note: $result is returned correctly, so is the query into the database. It's really just the last mail() step that sometimes does and sometimes doesn't work.

I would check the return value from mail(). It could be that your hosting provider is putting too much stress on the mail server and it's not just responding, but because you're not checking the return value from mail() you never know. I would log it with error_log() though, there's no need to tell the user there was an error when the insert still worked.

Thank you for the fast response, I put both a error log and return on the mail function. I noticed that even when mail() returns true (And no errors are logged) I'm not receiving the email.

So now my best guess would be that the host is the problem..

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.