help with mail():PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

help with mail():PHP

Post by raghavan20 »

Hi, I am trying to send mail using the mail() function and I am not able to do it. I suspect that I havenot mentioned the SMTP address. The SMTP address is "mail.allhyper.com". I dont know where to give this information within the php code.

The actual running file can be found at: http://raghavan.allhyper.com/sendMail.php

I would appreciate help regarding the issue.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Send Mail</title>
<link href="cms.css" rel="stylesheet" type="text/css" />
</head>

<body>
<center>

<table width = '600' cellspacing = '1' class = 'bordersOnly' style = 'margin-top:5px'>
<form name="frmMail" method="post" action="">
<tr class = 'commonHeader'><td colspan="2" class="Calign">Send Mail</td></tr>
<tr><td width="120" class="Ralign">To:</td><td><input type="text" name="txtTo" value="<? echo $_GET["recipient"] ?>" size="65"></td></tr>
<tr><td width="120" class="Ralign">Subject:</td><td><input type="text" name="txtSubject" value="" size="65"></td></tr>
<tr><td width="120"class="Ralign">Message:</td><td><textarea name="txtMessage" rows="15" cols="50"></textarea></td></tr>
<tr><td></td><td><input type="submit" name="subMail" value="Send Mail"></td></tr>
</form>
</table>
</center>
</body>
</html>
<?
if ($_POST["subMail"] == "Send Mail") {

// to
$to = $_POST["txtTo"];

//the subject
$subject = $_POST["txtSubject"];

// the message
$message = $_POST["txtMessage"];
$message = wordwrap($message, 70);

// Send
echo mail($to, $subject, $message);
}
?>
Raghavan
Last edited by raghavan20 on Wed Jun 22, 2005 11:17 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Do you get an error? What is it if so?

The SMTP server name is set in php.ini (if you own the server).

Note: The link above is dead....
404 Error wrote: Not Found
The requested URL /sendMail.php. was not found on this server.

Apache/1.3.33 Server at raghavan.allhyper.com Port 80
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

sorry there was a problem with the link then but now it works, it doesnot give any error message when I try to send a mail. I dont own the server as I host for free on allhyper.com's server.

So, can I infer that I dont have to set the SMTP? Then, what should be the problem with the mail()?
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

the link still doesnt work
asmie
Forum Newbie
Posts: 11
Joined: Mon Jun 20, 2005 8:45 am

Post by asmie »

Hie
I tested your code on my server and it seemed to work fine. I got the mail I had sent. However, check if you are applying and \n in the Subject.
Also check for html content in your message. Coz if there is html content then, you will have to specify the headers for the mail.

The php manual mail function has info to send the html mail headers. You can check that out .


As regards the link , remove the "." and it will work.
http://raghavan.allhyper.com/sendMail.php is the correct link ;)
Typo i guess .


A s m i e
User avatar
zippee
Forum Newbie
Posts: 9
Joined: Wed Jun 22, 2005 6:28 am
Location: England

Post by zippee »

Make sure the hosting support smtp. Otherwise no mail will send out.

The "echo2 before mail function is not necessary.
Post Reply