Jump to content

Recommended Posts

Hi all,

I have a form that captures data and then updates a db. On the same page that it updates the db, I'm trying to get it to email some of the form information.

 

As a test, I put together a simple mail test page to see if it would send email at its most basic form. Alas, it is not sending anything. I've tried multiple email boxes to no avail. My site is hosted on one of the many linux hosting sites out there. I have checked the phpinfo() and it appears that mail is turned on. I am assuming that when the page loads, it reads through the script, and runs the mail function. Can someone review my code below and confirm it is ok or not.

 

This is the php page in its entirety

<?php
//multiple recipients
$to="my@email.net";


//subject
$subject="test";

//body
$message="test body";
$from="where@sentfrom.com"; 
$headers="From: $from";
//mail it
mail($to, $subject, $message, $headers);
echo "Mail Sent.";


?>

 

If the above code looks ok, what else could cause the issue of not mailing? What else should I be looking at.

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/131674-stumped-by-simple-email/
Share on other sites

There is nothing wrong with your script. If it works without the $header variable being passed, then that means your host doesn't allow you to use a "From" address that it doesn't recognize. Setup an account like info@yourdomain.com and use that email as the From.

 There is nothing wrong with your script.If it works without the $header variable being passed, then that means your host doesn't allow you to use a "From" address that it doesn't recognize. Setup an account like info@yourdomain.com and use that email as the From.

It could be more than that, it could be like my host which will only allow an email account set up on them to be used, or for all we know the mail feature might be disabled by the host for his account type.

Edit: If it works without the $header variable being passed, then that means your host doesn't allow you to use a "From" address that it doesn't recognize.

You failed to mention what i did above, that's all i was pointing out, no need to get defensive.

First - I added the error checking, it returns nothing. I took out the header tages and just sent the to, subject and message - and I still get nada.

 

Second - I can't control my php.ini file. What setting should I look for on the phpinfo() output to confirm or unconfirm the mail settings.

 

Third - I do all my data gathering and db submission via php, I just want the confirm page to send and email, is there a better way to do this, or another way?

The only other thing I can think of is to check your SPAM filter on your email (if you have one).

 

Is this through a hosting service? If so, you should contact them. Your script is fine. Nothing looks out of the ordinary. The Tech Support there will be able to tell you if they configured the mail improperly or if your messages are being blocked. Who is the hosting with out of curiosity?

I just put in a support ticket with my hosting company. I'd rather not name names at this point.

 

thanks for everyones input, I'll update post as soon as I go over my account with support.

 

I did create an account specific to this domain, and it wouldn't email to it either. I'm not even using FROM anymore. Just trying to keep as simple as possible just to prove it can send mail.

Funny findings. PHp mail() is working. The script I have put up top does send email to my work account, but does not send to my host account or any yahoo.mail accts. Go figure. Waiting for response back from host as to why?  Little hard to test when I am at home working on this and it won't send to any account I have on home machine. Fun.

I wonder if my host email acct and my yahoo email need specific header info to accept the message. My outlook express does not contain a spam folder for my host account but my yahoo does and the message doesn't show up there.

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.