Jump to content

Email won't send with php


Howlin1

Recommended Posts

Hello,

I have a registration page and when a user registers I want to send their email an activation code.

To test I have the following code.

<?php
//Send activation Email

$to = $Email_address;

$subject = "www.WEBSITE.com/";

$message = "Welcome to my website!\r\rYou, or someone using your email address, 
has completed registration at WEBSITE. You can complete registration by clicking the 
following link:\rhttp://www.WEBSITE.com/register.php?action=verify&$activationKey\r\r
If this is an error, ignore this email and you will be removed from our mailing list.\r\rRegards,\ ";

$headers = 'From: noreply@abc.com' . "\r\n" .

    'Reply-To: noreply@abc.com' . "\r\n" .

    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

if (mail($to, $subject, $message, $headers))
{
    echo 'Success';
}
else
{
    echo 'Error';
}
?>

I have the last if else to see if it is sent to not. I do get a Success message, but I don't get an email at the address (I have checked the spam folder). I have checked the email address and it is correct. I have even waited a few hours and nothing.

Why is the email not getting to my account?

Link to comment
Share on other sites

Well, acording to this script, $to isn't actually set to anything because either is $Email_address.

 

Also, your check is almost right. The way you have it would send two emails if it was working. It can be one of two ways:

 

if (mail($to, $subject, $message, $headers)) {
//error
} else {
//success
}

in which case you don't need the first mail() call.

 

Otherwise you can do it like this:

$check = mail($to, $subject, $message, $headers)
if (!$check) {
//error
} else {
//success
}

Link to comment
Share on other sites

Well, acording to this script, $to isn't actually set to anything because either is $Email_address.

I didn't put the full script because it wasn't really needed, but there is a  value for $Email_address.

Well, acording to this script, $to isn't actually set to anything because either is $Email_address.

I didn't put the full script because it wasn't really needed, but there is a  value for $Email_address (but it's an attachment now).

 

if (mail($to, $subject, $message, $headers)) {
//error
} else {
//success
}

in which case you don't need the first mail() call.

 

Otherwise you can do it like this:

$check = mail($to, $subject, $message, $headers)
if (!$check) {
//error
} else {
//success
}

I only put that in to see if it was saying it was sent. It will be taken out as soon as it does actually work.

 

 

if (mail($to, $subject, $message, $headers)) {
//error
} else {
//success
}

in which case you don't need the first mail() call.

 

Otherwise you can do it like this:

$check = mail($to, $subject, $message, $headers)
if (!$check) {
//error
} else {
//success
}

I only put that in to see if it was saying it was sent. It will be taken out as soon as it does actually work.

 

[attachment deleted by admin]

Link to comment
Share on other sites

your code

$headers = 'From: noreply@abc.com' . "\r\n" .    'Reply-To: noreply@abc.com' . "\r\n" .    'X-Mailer: PHP/' . phpversion();

Replace this code

		$headers = "MIME-Version: 1.0\r\n";
	$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
	$headers.= "From: $from\r\n";

Link to comment
Share on other sites

@ DevilsAdvocate

I did echo out the variables and they contain what they are meant to contain. I even removed everything in the script and put in information myself, and still nothing.

I have added the full script as an attachment.

 

@voip03

I did that and still nothing.

 

[attachment deleted by admin]

Link to comment
Share on other sites

I got a reply back. I can send an email to a hotmail account but not a gmail account.

Me: What would the reason behind the email not being sent to the gmail account?

Host: That's generally a mystery deep in the mind of Google I'm afraid. Getting any sort of visibility out of them on that is an eternal struggle.

 

To me that sounds like they don't know. It looks like I'll have to (try) email google and ask them :/

Link to comment
Share on other sites

Is the From: header set to a valid email address on your server? Many times emails are dropped when the From: address doesn't resolve back to the sending server. In other words, the From: header should not be set to the address the user entered in the form.

Yes. The emails will deliver to a hotmail email (granted they get sent to the junk mail) but not a gmail one.

 

@Jacbey I tried that form and it wouldn't send it to my email address.

Link to comment
Share on other sites

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.