Page 1 of 1

help with mail():PHP

Posted: Tue Jun 21, 2005 4:40 pm
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

Posted: Tue Jun 21, 2005 7:12 pm
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

Posted: Tue Jun 21, 2005 11:26 pm
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()?

Posted: Wed Jun 22, 2005 12:16 am
by method_man
the link still doesnt work

Posted: Wed Jun 22, 2005 5:47 am
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

Posted: Wed Jun 22, 2005 6:45 am
by zippee
Make sure the hosting support smtp. Otherwise no mail will send out.

The "echo2 before mail function is not necessary.