Jump to content

Recommended Posts

I am trying to send an email based on a form. I am using this script, but I do not get any emails:

 

<?php

$to = "my@my-site.com";

$subject = "Hi!";

$body = "Hi,\n\nHow are you?";

if (mail($to, $subject, $body)) {

  echo("<p>Message successfully sent!</p>");

} else {

  echo("<p>Message delivery failed...</p>");

}

?>

 

What is the problem? any other ways to send mails via PHP?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/83473-email-function-do-not-work-what-to-do/
Share on other sites

Hmm, thanks.

 

I do not use AOL and I just added a "from" like this:

 

<?php

$to = "mymail@example.com";

$subject = "Hi!";

$body = "Hi,\n\nHow are you?";

$from = "Sandra Sender <sender@example.com>";

 

if (mail($to, $subject, $body)) {

  echo("<p>Message successfully sent!</p>");

} else {

  echo("<p>Message delivery failed...</p>");

}

?>

 

Stil no mail in my inbox.

 

The script comes on a page after a form. URL like this http://www.my-site/send1.php?websted=hi&email=example@example.com

 

But that should not cause any problems?

 

Any other way to send a mail via PHP?

 

Best

 

Cromagnon

You need to add the $from to your mail() function and format it like

 

$from = "FROM: Sandra Sender <sender@example.com>";

 

 

if (mail($to, $subject, $body, $from))

 

I know I'm just being picky, but the fourth argument isn't a from argument but a header argument and what you do is that you are adding the From header.

Never said it was a from arguement, I just said FROM was required.

 

You need to add the $from to your mail() function and format it like

 

$from = "FROM: Sandra Sender <sender@example.com>";

 

 

if (mail($to, $subject, $body, $from))

 

I know I'm just being picky, but the fourth argument isn't a from argument but a header argument and what you do is that you are adding the From header.

Look at his code above, all I did was include his variable in his mail() function, since he didn't.

 

Sure I could have renamed his $from variable to $header, and then did it, but then it's just a name.  I could have also provided a link to the mail() function and let him figure it out for himself too.

 

You implied it with your code, but whatever.

I'm still waiting to hear which one of the following messages are output by the code like Daniel0 asked in his first post in the thread - Message successfully sent! or Message delivery failed... Because that would help pin down where the problem is.

 

Also, check your web server log for errors.

 

 

I'm still waiting to hear which one of the following messages are output by the code like Daniel0 asked in his first post in the thread - Message successfully sent! or Message delivery failed... Because that would help pin down where the problem is.

 

Also, check your web server log for errors.

 

He did resolve his problem, but just didn't click "solved".

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.