Jump to content


Photo

mail function not working correctly


  • Please log in to reply
11 replies to this topic

#1 shaunmckinnon

shaunmckinnon
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 26 April 2006 - 04:37 AM

prolly stoopid me:

here's what's happening:
wrote a simple mail script just to check the sending capabilities. mail refused to send. tried over and over again, still wouldn't send. sent to hotmail box instead of my outlook account. found it in the junk mail folder. thought "all right, maybe it's harder now."
went to a forum to see if anyone else has had this issue. found this script.
<?
$mailtext = 'whatever';
$mailto = 'myemail@here.com';
$mailsubject = 'Us - Contact us enquiry';
$mailheaders .= "From: Shaun McKinnon Enquiry <myemail@here.com>\r\n";
$mailheaders .= 'MIME-Version: 1.0' . "\r\n";
$mailheaders .= 'Content-Type: multipart/mixed' . "\r\n";
$mailheaders .= " boundary=\"$mime_boundary\"";
$mailheaders .= "Reply-To: myemail@here.com\r\n";
$mailheaders .= "Return-Path: myemail@here.com\n";
if ($errormessage == ''){
mail($mailto,$mailsubject,$mailtext,$mailheaders);
exit;
}
?>
checked it, still goes to the junk mail folder and doesn't even appear in outlook. I receive crap in my outlook daily, so it's not restrictions on the server we use for the website. Is there anything anyone might know that would cause this issue?

#2 JRS

JRS
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 26 April 2006 - 04:49 AM

[!--quoteo(post=368734:date=Apr 26 2006, 12:37 AM:name=shaunmckinnon)--][div class=\'quotetop\']QUOTE(shaunmckinnon @ Apr 26 2006, 12:37 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
prolly stoopid me:

here's what's happening:
wrote a simple mail script just to check the sending capabilities. mail refused to send. tried over and over again, still wouldn't send. sent to hotmail box instead of my outlook account. found it in the junk mail folder. thought "all right, maybe it's harder now."
went to a forum to see if anyone else has had this issue. found this script.
checked it, still goes to the junk mail folder and doesn't even appear in outlook. I receive crap in my outlook daily, so it's not restrictions on the server we use for the website. Is there anything anyone might know that would cause this issue?
[/quote]
Shaun,
Don't know what the problem is, but my advice is to download PHPMailer from sourceforge.net and use it. I spent countless hours trying to figure out these stupid mail headers - it's not worth the trouble. There is a tutorial on this site that takes you step by step through PHPMailer - took me 30 minutes to download, setup and start mailing (attachments, HTML, plain text).
Good luck
JRS

#3 shaunmckinnon

shaunmckinnon
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 26 April 2006 - 05:01 AM

[!--quoteo(post=368736:date=Apr 26 2006, 04:49 AM:name=JRS)--][div class=\'quotetop\']QUOTE(JRS @ Apr 26 2006, 04:49 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Shaun,
Don't know what the problem is, but my advice is to download PHPMailer from sourceforge.net and use it. I spent countless hours trying to figure out these stupid mail headers - it's not worth the trouble. There is a tutorial on this site that takes you step by step through PHPMailer - took me 30 minutes to download, setup and start mailing (attachments, HTML, plain text).
Good luck
JRS
[/quote]
thanks, that's what i'll do i guess. it seems to me only last year that all you had to do was go mail($to, $subject, $body); and you were done. oh well. thank again.


#4 JRS

JRS
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 26 April 2006 - 02:20 PM

[!--quoteo(post=368738:date=Apr 26 2006, 01:01 AM:name=shaunmckinnon)--][div class=\'quotetop\']QUOTE(shaunmckinnon @ Apr 26 2006, 01:01 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
thanks, that's what i'll do i guess. it seems to me only last year that all you had to do was go mail($to, $subject, $body); and you were done. oh well. thank again.
[/quote]

Yes, you are right. The problem is when you add the 4th parameter $headers - then everything breaks or sometimes works.
JRS

#5 freshrod

freshrod
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 26 April 2006 - 02:28 PM

I'm relieved to see you guys are having problems with mail as well. In every tutorial, book, article, whatever I read, they make it sound like sending mail with the 'mail()' function is the easiest thing in the world.

But I've tried and tried, and even simple code like this:
<?php

// Your email address
$email = "freshrod@freshrod.com";
// The subject
$subject = "testing";
// The message
$message = "I hope this works!";
mail($email, $subject, $message, "From: $email");
echo "The email has been sent.";

?>

just doesn't seem to work.
Nothing is foolproof to a talented fool.

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 April 2006 - 03:53 PM

[!--quoteo(post=368843:date=Apr 26 2006, 03:28 PM:name=freshrod)--][div class=\'quotetop\']QUOTE(freshrod @ Apr 26 2006, 03:28 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I'm relieved to see you guys are having problems with mail as well. In every tutorial, book, article, whatever I read, they make it sound like sending mail with the 'mail()' function is the easiest thing in the world.

But I've tried and tried, and even simple code like this:
<?php

// Your email address
$email = "freshrod@freshrod.com";
// The subject
$subject = "testing";
// The message
$message = "I hope this works!";
mail($email, $subject, $message, "From: $email");
echo "The email has been sent.";

?>

just doesn't seem to work.
[/quote]
Are yoy running that code on a local setup of Apache/PHP? If you are then you will need to configure PHP to use an SMTP server in order for emails to be sent! You can configure the SMTP server in php.ini file.

If you are running it off your webhost then it should work or your webhsots has disabled the use of using th mail function.

#7 freshrod

freshrod
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 26 April 2006 - 06:14 PM

[!--quoteo(post=368880:date=Apr 26 2006, 10:53 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 26 2006, 10:53 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Are yoy running that code on a local setup of Apache/PHP? If you are then you will need to configure PHP to use an SMTP server in order for emails to be sent! You can configure the SMTP server in php.ini file.

If you are running it off your webhost then it should work or your webhsots has disabled the use of using th mail function.
[/quote]

Duh-Oh! They don't call me nOOb for nothing.

Thank you wildteen88!
Nothing is foolproof to a talented fool.

#8 missyevil

missyevil
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 28 April 2006 - 10:54 PM

Hi!

I'm having issues with the mail function too, and I'm not sure if its me being really *really* stupid, or my system is shafted.

I have the simplest bit of code ever that is just:

mail("$email", "Hello!", "This is the content of the message",
                                         "From: Webmaster<$from_email>");

I'm just running it locally at the minute, and I have configured my php.ini file so that "SMTP = localhost" and "smtp_port = 25", but I'm still gettin an error when I try to run it!!

This is the error in case it helps:
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:\Program Files\Apache Group\Apache2\htdocs\Project\mail.php on line 5

I'm totally stumped. Everythin I've read seems to say that this should work fine - its the simplest thing the mail function can do!!

Help??

#9 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 29 April 2006 - 03:44 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]This is the error in case it helps:
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:\Program Files\Apache Group\Apache2\htdocs\Project\mail.php on line 5[/quote]
You are obviously running on a Windows box. Do you have a Mail Server running on the box. Most likely, the answer is no. That's why you're getting the error.

Ken

#10 missyevil

missyevil
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 29 April 2006 - 11:21 AM

Ahhh, thank you Ken!

This really isnt as easy as I first hoped...

Anyone suggest the easiest way of setting this up? I really am completely new to all this!

#11 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 April 2006 - 02:46 PM

In order to use the mail function you will need to point php to a local/public SMTP server, one that doesn't require a login. Usually you'll find your ISP will have one and the address is something along the lines of smtp.ispname.com

YOu can setup the smtp server address in the php.ini file. Open the php.ini file for editing and find the following line:
SMTP = localhost
change localhost to the smtp servers address.

Now save your php.ini anmd restart your Apache web server.

#12 missyevil

missyevil
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 29 April 2006 - 05:42 PM

Thanks :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users