Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Please tell me i have the confusion in the coding please see

the mail() function

Moderators: macek, egami, gesf

Please tell me i have the confusion in the coding please see

Postby 1987ksr » Tue Aug 09, 2011 12:22 am

1.This type of coding is working

<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>

2. this type of coding is not working

test_mail.php

<!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 content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>test MAIL</title>
</head>

<body>

<form id="test" name="test" method="post" action="sent.php">
<table style="width: 52%">
<tr>
<td>To:</td>
<td><input id="sendto" name="sendto" type="text" size="50" />&nbsp;</td>
</tr>
<tr>
<td>Subject:</td>
<td><input name="subject" id="subject" type="text" size="75" />&nbsp;</td>
</tr>
<tr>
<td>Body:</td>
<td><textarea name="body" id="body" rows="4" cols="30" onkeydown="limitText(this.form.body, this.form.countdown1, 144)" onkeyup="limitText(this.form.body, this.form.countdown1, 144)"></textarea> <br/>
<font size="1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Maximum characters)</font>
<input readonly type="text" name="countdown1" size="3" value="144" style="width: 35px" />
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="Submit1" type="submit" value="Send" />&nbsp;</td>
</tr>
</table>
<script type="text/javascript">

function limitText(limitField, limitCount, limitNum)
{
if (limitField.value.length > limitNum)
{
limitField.value = limitField.value.substring(0, limitNum);
}
else
{
limitCount.value = limitNum - limitField.value.length;
}
}
</script>
</form>
</body>

</html>

sent.php


<?php
$to =$_POST['sendto'];
$subject =$_POST['subject'];
$body =$_POST['body'];
$frommail="SHIROTECHNOLOGY";
if(mail($to,$subject,$body))
{
echo "Mail Sent";
echo "<script> location.href='test_mail.php';</script>";

}
else
{
echo "Mail Not Sent";
}
?>

[/u][/b]
1987ksr
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Aug 09, 2011 12:16 am

Re: Please tell me i have the confusion in the coding please

Postby bigjoe11a » Tue Sep 27, 2011 1:08 pm

I'm shocked that the 1st one works.

Try this below

Code: Select all
<?
    //change this to your email.
    $to = "m@maaking.com";
    $from = "m2@maaking.com";
    $subject = "Hello! This is HTML email";

    //begin of HTML message
    $message = "<html>
  <body bgcolor=\"#DCEEFC\">
    <center>
        <b>Looool!!! I am reciving HTML email......</b> <br>
        <font color=\"red\">Thanks Mohammed!</font> <br>
        <a href=\"http://www.maaking.com/\">* maaking.com</a>
    </center>
      <br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
  </body>
</html>";
   //end of message

    // To send the HTML mail we need to set the Content-type header.
    $headers = "MIME-Version: 1.0rn";
    $headers .= "Content-type: text/html; charset=iso-8859-1rn";
    $headers  .= "From: $from\r\n";
    //options to send to cc+bcc
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
    //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
   
    // now lets send the email.
    mail($to, $subject, $message, $headers);

    echo "Message has been sent....!";
?>
User avatar
bigjoe11a
New php-forum User
New php-forum User
 
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron