PHP email is sent but data isn't displayed everywhere

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.

‘Great minds’ and all that 8)

Kevin and Redscouse… Thanks for you comments. This process was a long one and I did not want to mix
up Jeff as he appears to be a newbie… It is working for him as far as code goes. I think his only issue is
the Hotmail account at this point. So, the last few messages were about how to debug those issues.

He emptied out the posted variables so that nothing was put into the fields when the page first is opened.
Then, the posted values are pulled and displayed. So, when the email is sent, it contains the valid new
data that is loaded and not other older data stays in fields. And, yes, short-code versions are good if you
know how to handle it. Jeffery will learn how to do this at some time. I do think it is easier to understand
doing it his way, though. Especially if you are showing the code to others.

As always, nice to hear from others on the site. A good mix of info and thoughts are good for programming!
CYA in the bitstream…

If Jeff is a newbie, this is probably the best time to teach him to do it properly - not just ‘get it working’

I seem to recall having an issue sending to a hotmail account using php’s mail() function - turns out they block any domains with no SPF record, you can create one here.

Hope that helps,
Red :wink:

Thanks, Redclouse !

Jeffery was supposed to be testing it with a Yahoo or Gmail account, but, he has not responded back
as yet.

So, Jeffery, did you see Redclouse’s reply with the link about fixing Hotmail emails from PHP???
Hope you did…

And, yes, perhaps doing things correctly should be in every post…

Never heard of him. :stuck_out_tongue: 8)

He is the Santa version.

LOL, sorry Redscouse… Fly’n Fingers…

Sorry, I didn’t notice the answers… Somehow I missed a notification…

I seem to recall having an issue sending to a hotmail account using php's mail() function - turns out they block any domains with no SPF record, you can create one here.

I’ve visited the link a couple of times, keeps saying System Maintenance in progress. Please try again later.. So I can’t use it. Thanks for helping me though! :slight_smile:

I’ve tested the page with several emailaddresses:

[email protected] (that’s the one which receives the confirmation, which is used in the code)
[email protected] (just created a new one)
[email protected]
[email protected]
[email protected]

All the times an email was sent to [email protected]. So I always receive a copy, this works.

If I use [email protected] as visitor email:
Everything works perfect.

If I use [email protected] as visitor email:
No email received on hotmail. Spambox is empty. An error is sent to my server.

If I use [email protected] as visitor email:
No email received on GMail. Spambox is empty. No error is sent to my server.

If I use [email protected] as visitor email:
Email received on Yahoo, not in inbox but in spamfolder. No error is sent to my server.

So the problem is obvious the structure of the email, the way it is build, because it’s recognized as SPAM by most common mail providers.

before i found out about the hotmail spf thing, the workaround i used was to create a mailbox on my server which auto forwarded to the hotmail account.
Then using php mail() i’d send to the account on my server (then let it do it’s thing forwarding the message on to hotmail)

Rough, but works.
Red :wink:

Jeffery,

If a few email addresses work, then, most likely, you do not have your server’s SMTP set up correctly.
What server host are you using? If it is your own server, you can set up the SMTP using your own email
system instead of your server’s.

If you are using a hosting system, then you should ask them why some of your emails do not send.

It is an SMTP set up issue or you are using invalid headers for your PHP mail system.

Hope that helps…

Happy holidays!

Got back from christmasholidays, straight back to my mail issue… This site from microsoft’s still down. Can’t try this solution. I’m using a hosting system. I tried to change the headers, I’ve set them to text/html, still with the same results.

The only headers I’m using are:

[php]$email_headers = “From: my name”."\r\n";
$email_headers .= “Reply-To: “.$replyTo.”\r\n”;
$email_headers .= “MIME-Version: 1.0”."\r\n";
$email_headers .= “Content-Type: text/html; charset=utf-8”."\r\n";[/php]

Beneath those headers the message’s loaded.

Well, those look good to me. Not sure what link you are talking about at MS that is down.

I still think it is a “REDIRECTION” problem. Most servers have protection that does not allow a user
to send messages to them redirected from another server. They do check the incoming message’s
sending server against the return address. This is to protect servers from spammers. It might be
the issue. I spent about 30 seconds with our friend “Google” and found this fix for it. It is actually
a fix for just the error#RFC-5322, but that is most likely your problem. Since you never reviewed your
server’s mail logs as we suggest, I bet it is that error.

To fix it, try changing your header to use this format instead of yours:
$headers = “From: my name [email protected]” . “\r\n”;

This tells the Hotmail’s mail server that the message is directly from you not from an unknown address.
In that way if they have any issues, they know who mailed the message. Hot that works for you!

OH, also, if you need the reply to go somewhere else, make sure the reply-to is accurate…

[member=43746]ErnieAlex[/member] ,

You hit it right here:

Since you never reviewed your server's mail logs as we suggest

This is obviously a server configuration situation. The error/mail logs will clearly show what is going on.

Sponsor our Newsletter | Privacy Policy | Terms of Service