PHP email is sent but data isn't displayed everywhere

One more thing, the reason the email address for the user is not sending is because the variable not
being set inside the function. (Same issue as the first name variable.) So, fixing that should send out the
email correctly. Your email is hard-coded outside of the function, so not sure why that is working.

But, let us know how it is going…

but the email is passed on in the SendEmail, look:

[php]SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, true);[/php]

here it sends the $visitor_email.

The function puts this value into the $mailto, like this:

[php]function SendEmail($mailto, $subject, $title, $orderid, $timestamp, $maskcardno)[/php]

also, like I wrote in previous message, I do get an error mail send back to me. If I open this email, it sais it cannot send to the emailaddress.

(Mail Delivery System; Message could not be delivered. Please ensure the message is RFC 5322 compliant). This error mail does echo the mailaddress of where the email should have been send to, it just doesn't deliver it at that specific mailaddress...

Well, perhaps I was not clear enough. If you receive that error, then it is NOT getting the TO: address.
To debug this, just add a line to your code and retry it. If it is the correct email address, then it is not
passing it to the function correctly.

So, change the sending line to include this: ( It will make the code stop at that point and display the email)
[php]
die("Email is: " . $visitor_email);
SendEmail($visitor_email, $subject, $title, $orderid, $timestamp, true);
[/php]
I use the “die” command function to debug data when testing. If the visitor’s email is correct, then, it would
mean that the function is bad as it forwards the email to the function. I reviewed all of the code that you
posted and it does look correct. So, either the email address is not being passed or it is a bad email
address. To test that, try to send the email and type in your own email address.

I have to leave for a few hours. Good luck.

Thank you, I’m gonna take a close look at the function, because when I add the ‘die’ part to the code, the email is displayed as it should. The email is displayed on my screen.

it has something to do with predefining both emails. At the top I’ve $LMEY_email pre-set. This is possible because this is always the same emailaddress. If I move this line and put in between all other variables that are created as soon as the submit button’s pressed, I get an error on the screen.

If I add the “die” part inside of the function, the email’s also displayed correctly.

[php]function SendEmail($mailto, $subject, $title, $orderid, $timestamp, $maskcardno)
{
die("Email is: " . $mailto);[/php]

this echoes the data that is set in $visitor_email, so also inside of the function it still gets the right data. The emailaddress is functioning too, it is my own emailaddress I’m using to test this, so no mistakes on a non-functioning emailaddress. It just doesn’t reach it.

Well, that actually is good news. So, it is some other line of code in the function causing the error.

It might be this line:
$message .= $cart[PRODUCTNAME][$i][‘eventnaam’]."\t";
no quotes around the productname?

How to debug this would be to move the DIE line down a few lines at a time and see exactly which line
of the function is causing the error. Will take a bit of time, but, then you can find the bad line.

Hope that helps!

I used the die function behind every single line of code, displaying the right value every single time. I even tried to combine parts, also with positive results.

[php]die("mailto: " . $mailto . " subject: " . $subject . " message: ". $message . "emailheaders: " . $email_headers);[/php]

the above code echoed all the correct data.

What I still don’t understand; it is just one function, which is called twice. The way the function’s called doesn’t change after the first time. Also the content of the function or anything inside of it doesn’t change after it’s called the first time. How is it possible that I don’t receive any errors when it is executing the SendEmail to me (and send all data the way it should be sent), but does give problems when it should be sent to the customer?

All email fields receive the emailaddress that is filled in on the form, as I tested the script with the die function.

frustating

Yes, for me too as I wish I could see the error for you. I just do not see anything wrong in it.

So, once again, are you 100% sure that the email addresses that you are using are valid?
Did you try to email directly to both of them to test it? I will put the routine onto my server and
test it, but, I just do not see where the error is…

Hey, wait, did you happen to check your spam filter on the other email address? Perhaps it is just
stashing the email in your spam folder? Worth a check…

I own you an apology. I kept on testing the script with the same emailaddress. I’m created a new one on my server, if I use this one on the form everything works. Really everything. So, it seems the script isn’t the problem, outlook is. I’ve tested the script with 2 hotmail accounts, both failed to receive the email. If I use my own account (with 2 different mailaccounts) everything works just perfect. So I searched google for any similar problems, didn’t get any further. It has something to do with RFC 5322 compliant. Somehow the mail’s blocked by outlook’s server. I didn’t find any solution on the internet that could help me on this problem. Do you know a way to pass it beyond outlook’s Alcatraz doors?

LOL, well, very very glad that you have the email part working.

Now, there are several things that can stop Hotmail from passing the email back to Outlook.
First, you should log into the Hotmail.com website and check your SPAM filters. Look in the SPAM folder
and see if the emails are in there. Quite often Hotmail will lock out an email if it thinks it is SPAM. On their
site, there is a way to alter your SPAM options. You might have to mark your server’s address as okay to
get mail from. Or, just lower the SPAM settings.

Another issue is the PORT numbers in Outlook might not be set up correctly. You can test both of these
issues by just sending yourself an email to the Hotmail address. Inside of Outlook, send out an email to
the Hotmail address. See if it comes back to your Outlook. If it does not, then you either have a SPAM
filter issue or your Hotmail account is not set up correctly inside of Outlook.

Not sure if that helps or not, but, try to send yourself an email from Outlook to the Hotmail address and
see if you get it back. If so, then the headers in the PHP code must be altered a little so Hotmail can read
them. And, if it does not come back, it is either spam filters or outlook account settings.

Let us know…

My SPAM folder is empty. No messages in here. I’ve checked this folder daily but that’s not the problem. My server emailaddress is on the safelist too. The email address I was testing with is my personal email, so I use this one daily. If I send myself an email I don’t experience any problems. So my guess is that the headers needs to be modified.

Well, so we ruled out just about everything. Try doing this last test. in your code in the SendMail function,
replace the two mail() functions and hard-code in your email addresses. SO, change these:
mail($mailto, $subject, stripslashes($message), $email_headers);
mail($mailto, $subject, stripslashes($message), $email_headers);

TO these:
mail("[email protected]", $subject, stripslashes($message), $email_headers);
mail("[email protected]", $subject, stripslashes($message), $email_headers);

So, what this will do is make sure that it is the headers or not. Run your system. If you get two emails,
then it is your variable for the $mailto… (What we first thought was the problem.) If you get only the
one email, then we need to look at the headers, although at my first glance they look good.

My headers from a working version of this code is similar. Your headers are:
$email_headers = “From: Entertain You Events”."\r\n";
$email_headers .= “Reply-To: “.$mailto.”\r\n”;
$email_headers .= “MIME-Version: 1.0”."\r\n";
$email_headers .= “Content-Type: text/plain; charset=utf-8”."\r\n";
My headers are:
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= ‘From: Important Message from zzzzzz.com! [email protected]’ . “\r\n”;
In my version, I don’t bother with the reply-to as it uses the address sent from. I am using the HTML
MIME type which is the ISO-8859 version. You are using the MIME plain text version. As far as I know,
either of these should work correctly. So, I do not think it is the headers…

I still think it is something to do with the actual email address not being placed into the mail() function
correctly. Try the replacement of hard-coding the send-to address and see if you get two emails or not!

hard-coded email leaves me with the same problem. It does send to all my server emailaddresses, it doesn’t reach hotmail.

Good! Now, we know the code is solid and it is not your website code. ( Well, maybe…)

Since you can not send an email, it must be your outlook or your server. If you want to send me a copy of your form and PHP code, you can zip it up and attach it in a private message and I will test it on my server.
Just take out any passwords in the code. I will change the addresses to my email accounts and test it for
you. (I am gone the rest of day and night, so it would be tomorrow morning.)

If you want to add some error tracking in your mailing code, you can do so this way:
if (mail(…)) {
die(" Your email was sent!");
} else {
die(" Your email failed! ");
}

This type of code basically just lets you know if it is the mail function that failed or not. If you add the code
to the first email, it will tell you if it actually mailed the email or not. If it was sent, then it is your server or
your mail client. I did some further research for you and found this quote:

sending mail in php is not a one-step process. mail() returns true/false, but even if it returns true, it doesn't mean the message is going to be sent. all mail() does is add the message to the queue(using sendmail or whatever you set in php.ini)

there is no reliable way to check if the message has been sent in php. you will have to look through the mail server logs.


In further reading for you, it clearly states that the default PHP mail() function has no type of error tracking
built into it. There are many types of “libraries” that you can use that do full error tracking, but, it does not
appear to be needed. I found that mailing in PHP is usually done using the server’s “sendmail” function. If
you need to check that, you can place a line at the top of any of your pages to show ALL of your PHP
settings. ( use " phpinfo(); " ) You would have to look down the large list for the mailing options. Most
likely, you will find the server log file called “LOG_FILE” at some address like “/my/home/errors.log” … This
means that you need to log into your server’s control panel and look at that address whatever it is. Then,
you will see the errors.log file and you can VIEW it. Look at the bottom of it just after you send your emails.
You will see various logs of errors that the server views as errors or problems. If your mail system did really
have an error, it will be there. If not, then the problem is outside the server and that means either HOTmail
or your email client. TO check HOTMAIL, just change the address to another email account. Try setting up a
temporary email account at Gmail or Yahoo and test using that one. Just use the webmail service for the
one you pick instead of setting up Outlook to handle it. If it goes thru, then it is HOTMAIL. I have seen that
HOTMAIL sometimes do not allow redirection of emails from server to server, so it might be them. Reading
the emails using the webmail service instead of Outlook will rule out Outlook and the local machine it is on.
( webmail just means logging into HOTMAIL, Gmail or Yahoo and reading mail thru the browser! )

Now, that is just about EVERYTHING I know about mail servers. Hope somewhere inside this is the answer
for you. Let us know what happens next with your tests… Good luck!

As a side note to you both, using $GLOBALS is not great. It usually means the code hasn’t been thought through properly and is a last ditch effort to grab the variable you really needed in the first place.

Have a rethink guys, just my two-pence…
Red :wink:

Yep, Redcouse, it was a last ditch effort to sort out his errors. He does have the code working now and
should be without the $globals array. But, we finally narrowed it down to be outside his code and not a
programming issue. I suggested the $globals just to make sure he was loading the variable correctly.
(He gave the code in bits and pieces and finally sent me an entire copy in a PM which looks good now.)

If you read from start to end, I have been pointing out ways for him to “DEBUG” his code to locate the
errors, not really to give him a final product. His issues are outside the code, although we did fix a lot of
his general coding problems.

You mentioned rethinking our process. Do you have anything to add on how to fix his out-of-code
problems? What did I miss. All help is welcomed if you can add to the thread. Thanks!

Hi ErnieAlex :slight_smile:

TBH mate, I never read through the entire thread, just skimmed over and the word $GLOBALS just jumped out at me so i read that portion of the script.

There are many many issues - I assume you got them all as you went through 3 pages helping the OP.

The $GLOBALS part, why pass the variables into the function then use globals?
[php]
function SendEmail($mailto, $subject, $title, $orderid, $timestamp, $maskcardno)
{
$message .= “Aanvraagnummer: LMEY”.$GLOBALS[‘orderid’]."\r\n";
$message .= “Aanvraagdatum: “.$GLOBALS[‘timestamp’].”\r\n”."\r\n";
// etc. etc.

// why not:
function SendEmail($mailto, $subject, $title, $orderid, $timestamp, $maskcardno)
{
// notice the first period has been removed to start a new string…
$message = “Aanvraagnummer: LMEY $orderid\r\n”;
$message .= “Aanvraagdatum: $timestamp\r\n\r\n”;
// etc. etc.
[/php]

Another thing i don’t understand,
[php]define(“PRODUCTNAME”, 1);[/php]
What is the purpose of defining a constant to hold the value 1? It doesn’t make sense to me, you be better writing $cart[1][etc][etc] for the sake of clarity.

[php]// This is not ideal and could lead to parse errors
header("Location: ".“error.php?msg=”.rawurlencode(“Voeg aub eerst evenementen toe voordat u uw informatieaanvraag afrondt.”));

// try this: (cleaner, no?)
$string = rawurlencode(“Voeg aub eerst evenementen toe voordat u uw informatieaanvraag afrondt”);
header(“Location: error.php?msg=$string”);[/php]

Why do this:
[php]$firstname = ‘’;
$lastname = ‘’;
$straatnaam = ‘’;
$huisnummer = ‘’;
// etc. etc.

// Then this:

$firstname = $_POST[‘firstname’];
$lastname = $_POST[‘lastname’];
$straatnaam = $_POST[‘straatnaam’];
$huisnummer = $_POST[‘huisnummer’];
//etc. etc.[/php]
Pretty much a waste of time and space.

When the OP sent you the full script did you add to his? (probably would have been better to write your own from scratch)

Red :wink:

[member=26967]Redscouse[/member] , The below is actually necessary so you don’t get undefined index errors. The other way it could be done is it do an if(isset) on each one. I personally prefer not to created additional variables that are not necessary. One advantage to using as $_POST[‘firstname’] is you know exactly where the variable came from. The one exception would be is if you ran it through a sanitizer filter or function such as :

$sanitized_firstname= sanitizer($_POST[‘firstname’]);

I also have not read the entire thread. Seems awfully long for just trying to send an email though.

[php] $firstname = ‘’;
$lastname = ‘’;
$straatnaam = ‘’;
$huisnummer = ‘’;
// etc. etc.

// Then this:

$firstname = $_POST[‘firstname’];
$lastname = $_POST[‘lastname’];
$straatnaam = $_POST[‘straatnaam’];
$huisnummer = $_POST[‘huisnummer’];[/php]

Hi Kevin, Yes I know they’re written to avoid errors, I would have just done it a little differently.
[php] $firstname = isset($_POST[‘firstname’]) ? $_POST[‘firstname’] : ‘’; //(or false)

// or even:

foreach($_POST as $key => $data) {
$$key = trim(addslashes($data));
}

if(!isset($firstname)) {
echo ‘errors, firstname not set!’;
}

// etc. etc.
[/php]

‘Seems awfully long for just trying to send an email though.’ << couldn’t agree more ;D

I always try and keep things as simple as possible, makes it easier to read this time next year.
Red :wink:

[member=26967]Redscouse[/member] - I fully agree. I always try to do the shortest, cleanest, correct code possible.

Sponsor our Newsletter | Privacy Policy | Terms of Service