Jump to content

Email code not working


thefollower

Recommended Posts

I am wondering what this error means this is my first attempt at email...is there something i have not done in my settings?

 

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\test4.php on line 7

 

Message delivery failed...

 

<?php
include("include.php");

$to = "[email protected]";
$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>");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/79637-email-code-not-working/
Share on other sites

In your code..below there is a small error.

mail() function takes four parameters

1. to

2. subject

3. message

4. headers

 

for ex:- mail("[email protected]", "This is the subject", "Here will be your message", "From: [email protected]");

 

just execute the above function by giving a working email address in the place of [email protected], it doesnt matter from whom u r getting the mail and what is in the headers section (i.e .. [email protected]) ('From:'  should always be there as the fourth parameter. you can add more information to this parameter.. but for u the above function works fine)

and thats what the error message saying , lacking of the fourth parameter.

 

-------------------------------------got cleared ?

 

<?php

include("include.php");

 

$to = "[email protected]";

$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>");

}

?>

I did put a legit email i just changed it to [email protected] cos i did not want to put my email out in public..

 

 

 

<?php
include("include.php");

$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$From = "[email protected]";
if (mail($to, $subject, $body, $From)) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

 

Is that how it should be?

 

Stil gives me error even though i put the sender in...

 

Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\xampp\htdocs\test4.php on line 8

Message delivery failed...

How do i turn it on last time i fiddled with settings i totally screwed up my apache and had to re-install.. don't want to make same mistake twice.

 

I found this in my settings:

 

sendmail_from no value no value

sendmail_path no value no value

 

Though theres no option to just turn it on in apache :S

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\test4.php on line 8

Message delivery failed...

 

This is what i have:

 

<?php
include("include.php");

$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$From = "[email protected]";
if (mail($to, $subject, $body, "From: <$From>")) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

see man, let me explain u clearly.. with the xampp u have installed u will get the apache server, sql server and some other but not mail server. if the code u have given is correct, even if u r working locally(means on your local machine , not on a web hoster) u wont get any errors.

if there are any errors then it will show u them.(even if u r working on web server)

 

the mistake in your code as i have explained earlier is missing last parameter

 

ur code after modified.

 

<?php

include("include.php");

 

$to = "[email protected]";

$subject = "Hi!";

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

$From = "From: [email protected]";              //(this is how this line should be.. try this but not on your local machine

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

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

} else {

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

}

?>

 

 

you do one thing. login to www.x10hosting.com and create a login id. then he will give u a site name.. for ex. www.yourname.x10hosting.com

then go to your cpanel (http://yourname.x10hosting.com:2082) probably looks like this.. this cpanel link will be sent to u in your mail..

there u can upload your php pages (this is all free of cost.. thats a free site for web hosting)

 

there upload a file index.php and write your code in that file.

 

then access your site with www.yourname.x10hosting.com now if mail has been sent u will see success msg and if failed  , your failure message.

 

you can get the status of your mail function..whether its successfull or failure. by assigning  your mail function to a variable.

 

$ok = mail($to, $subject, $body, $From);

 

$ok will be TRUE if success, FALSE if failure.

 

 

hope this helped u.

 

 

 

 

see man, let me explain u clearly.. with the xampp u have installed u will get the apache server, sql server and some other but not mail server. if the code u have given is correct, even if u r working locally(means on your local machine , not on a web hoster) u wont get any errors.

if there are any errors then it will show u them.(even if u r working on web server)

 

the mistake in your code as i have explained earlier is missing last parameter

 

ur code after modified.

 

<?php

include("include.php");

 

$to = "[email protected]";

$subject = "Hi!";

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

$From = "From: [email protected]";              //(this is how this line should be.. try this but not on your local machine

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

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

} else {

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

}

?>

 

 

you do one thing. login to www.x10hosting.com and create a login id. then he will give u a site name.. for ex. www.yourname.x10hosting.com

then go to your cpanel (http://yourname.x10hosting.com:2082) probably looks like this.. this cpanel link will be sent to u in your mail..

there u can upload your php pages (this is all free of cost.. thats a free site for web hosting)

 

there upload a file index.php and write your code in that file.

 

then access your site with www.yourname.x10hosting.com now if mail has been sent u will see success msg and if failed  , your failure message.

 

you can get the status of your mail function..whether its successfull or failure. by assigning  your mail function to a variable.

 

$ok = mail($to, $subject, $body, $From);

 

$ok will be TRUE if success, FALSE if failure.

 

 

hope this helped u.

 

 

 

 

 

I did put $From ... see above.

 

How ever i did not know i needed a server for it. i thought it would work from localhost like everything else. I'll sign up to that site and try it out.

 

Will let you know.

hei, the follower...

 

u have added $From to your code..but see that state ment carefully

u have given like this

 

$from = "[email protected]";

 

but it should be like this

 

$from = "from: [email protected]";

 

this is becos, fourth parameter to mail function is not just the from parameter.. it contains more details like

 

from: "[email protected]";

to: "[email protected]"

mime: 1.0

and so...

 

the above all parameters combinely constitute the last parameter. its called headers.

 

u might have observed in your mail.. the details of the person who sent that mail, to whom., text type(html/plain)... and so.. these details are the $headers(the fourth parameter)

 

anyhow read the replies carefully.. even a dot in the place of coma will affect the code.

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.