Click to See Complete Forum and Search --> : code for sending mails


mayanksrmcem
09-04-2006, 12:57 AM
hi friends,

I need ur help.
I want to send emails through php code.
but there are some problems n i'm not able to understand the actual problems.
the code , i've used is as followes----

<?php
if (isset($_REQUEST['tsend']))
{
$to=$_REQUEST['tto'];
$sub=$_REQUEST['tsub'];
$mail=$_REQUEST['tmail'];
$mail=@mail($to,$sub,$mail,"mayank13dec@gmail.com");
if(!$mail)
{
$error = 'Error sending message!';
echo $error;
}
else
echo "mail send";
}
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>
<input type="text" name="tto">
</td>
</tr>
<tr>
<td>
<input type="text" name="tsub">
</td>
</tr>
<tr>
<td>
<textarea name="tmail"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="tsend" value="send">
</td>
</tr>

</table>
</form>

</body>
</html>


but after run the program the only error msg will be disply.
help me for solve this problem.
thanx

Sheldon
09-04-2006, 05:34 AM
$_SERVER['PHP_SELF']; is dangerous to use by its self.

$_REQUEST[''] is outdated, use in that case $_POST[''].


<?php
if (isset($_POST['tsend']))
{
$to = $_POST['tto'];
$sub = $_POST['tsub'];
$mail = $_POST['tmail'];
mail($to,$sub,$mail,"mayank13dec@gmail.com") or die ("Error sending message!");
echo("Mail Sent!");
}
// rest of script
?>

mayanksrmcem
09-04-2006, 06:02 AM
thanx sir,

but there is an errmsg as output---------------

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for mayank@mysite.com .
here mayank@mysite.com is an example for parameter "To".

help me for solve this prob.
thanx

DJsAC
09-04-2006, 07:03 AM
that will probably mean that the problem is not in the php code, but in the configuration of the mail module on the server ;)
Contact the server admin for more help about that, if you're the serveradmin, read apache's or IIS's manual for more info about mail relays.