Help - Search - Members - Calendar
Full Version: Php Mail
Sal's RuneScape Forum > Everything... Not RuneScape > Tech Talk > Programming & Web Development
Samarkov
Well, I'm teaching myself how to use the php mail system now, and even the first tutorial didn't work. Could anyone tell me what is up with it?
CODE
<?php
error_reporting(E_ALL);
$to = 'Samarkovian@yahoo.com';
$subject = 'The Rune Network';
$message = 'TEST';
$headers = 'From: Samarkov@TheRuneNetwork.com';
if(mail($to, $subject, $message, $headers));
{
echo 'MAIL SENT';
}
?>


No idea why this isn't working. slanty.gif

Thanks.
~~Samarkov king.gif
Yippee
OK, I don't see anything wrong with the code itself, although I haven't exactly learned the sending e-mails part of PHP. It's probably something else.

#1. Where are you trying to run the file from? Your computer can't run PHP unless you download the right software and stuff, which is just a pain. I strongly recommend just uploading the file to a webhost that supports a fairly recent version of PHP. I really like ByetHost, and it's free, but it might be a little difficult to figure out how to use it.

#2. Is the file saved with a .html or .php extension? Some (maybe most) browsers aren't configured to look for PHP code in .html files. Saving it as a .php might help.

#3. Do you have the normal <html> and <body> tags around it? PHP, when being used on the web, is made to be embedded inside normal HTML code. Sometimes it may work if you don't do this, I haven't actually tried it yet, but it's recommended.

I'll tell you if I come up with more. It would help those trying to help you if you gave more specifics. What isn't working about it? Is it just doing nothing, or is it giving you an error report, or something different? Where are you hosting the file and what browser are you using? Things like that.

Another thing that would help is if you changed the if statement to this:

CODE
if(mail($to, $subject, $message, $headers));
{
echo 'MAIL SENT';
} else {
echo 'SEND FAILED';
}


Run that and tell us if it prints SEND FAILED or not. If it does, then the e-mail just isn't being sent. Maybe an invalid e-mail address? If it doesn't, then you have a coding error somewhere.
iEthan
Do you have a IMAP or SMTP for your server setup? You can change it in httpd.conf php.ini. It is on line 556.

~iE

EDIT: Wrong file.
Samarkov
I'm running it from my server, it is saved as .php, and it was in between <html> tags.
Also, I cannot edit my php.ini file. slanty.gif Freehostia won't let me.
However, I do have SMTP turned on.

~~Samarkov king.gif
Fruitpastles
Your mail is probably being blocked by yahoo because it looks like it may be spam. You need to add more headers ( I forget which ones) or send it as a HTML email rather then just plaintext. Google will help you.
Samarkov
QUOTE (Fruitpastles @ Aug 1 2009, 07:36 AM) *
Your mail is probably being blocked by yahoo because it looks like it may be spam. You need to add more headers ( I forget which ones) or send it as a HTML email rather then just plaintext. Google will help you.

Thanks, I'll try that out.

~~Samarkov king.gif
Fruitpastles
No probs.

I checked the contact form I wrote for my site and the only headers I use are:

CODE
From: contact@craigkewley.com\r\nReply-To: contact@craigkewley.com
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.