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 = "test@gmail.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>");
}
?>

Link to comment
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("test@gmail.com", "This is the subject", "Here will be your message", "From: sender@gmail.com");

 

just execute the above function by giving a working email address in the place of test@gmail.com, it doesnt matter from whom u r getting the mail and what is in the headers section (i.e .. sender@gmail.com) ('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 = "test@gmail.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>");

}

?>

Link to comment
Share on other sites

I did put a legit email i just changed it to test@gmail.com cos i did not want to put my email out in public..

 

 

 

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

$to = "test@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$From = "sender@gmail.com";
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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 = "test@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$From = "sender@gmail.com";
if (mail($to, $subject, $body, "From: <$From>")) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

Link to comment
Share on other sites

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 = "test@gmail.com";

$subject = "Hi!";

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

$From = "From: sender@gmail.com";              //(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.

 

 

 

 

Link to comment
Share on other sites

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 = "test@gmail.com";

$subject = "Hi!";

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

$From = "From: sender@gmail.com";              //(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.

Link to comment
Share on other sites

hei, the follower...

 

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

u have given like this

 

$from = "xyz@abc.com";

 

but it should be like this

 

$from = "from: xyz@abc.com";

 

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

 

from: "xyz@abc.com";

to: "x@y.com"

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.

 

 

 

 

Link to comment
Share on other sites

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.