Sending email:

http://cisweb.bristol.mass.edu/~pgrocer/mail/basicemail.php

<?php

mail('', 'Test', 'This is a test.');

?>

http://cisweb.bristol.mass.edu/~pgrocer/mail/email.php

<html>

<head<title>email</title</head>

<body>

<?php

$to = "";

$subject = "PHP email";

$body = "PHP is a great language to work with on the web";

$headers = "From: \n";

mail($to,$subject,$body,$headers);

echo "Mail sent to $to";

?>

</body>

</html>

http://www.htmlite.com/php029.php

“Headers are the parts seen at the top of emails. Typically :

To : / A comma seperated list of recipient emails.
From : / The senders email address.
Reply-To : / The email address where replies should be sent to.
Return-Path : / Kinda the same thing as the Reply-To. Some email clients require this, others create a default.
Subject : / Subject of the email.
CC : / Carbon Copy. A comma seperated list of more recipients that will be seen by all other recipients.
BCC : / Blind Carbon Copy. A comma seperated list of more recipients that will not be seen by any other recipients.


The TO and SUBJECT fields have already been discussed as the first and second variables in the MAIL command. The extra headers seen above can be entered as a 4th variable in the MAIL command.

<?php
mail("","My email test.","Hello, how are you?","From: \r\nReply-To: \r\nReturn-Path: \r\nCC: \r\nBBC: \r\n");
?>


Looks kinda messy when it's all in there without using variables. That above example has all of the extra headers being declared. You may specify all or some or none as you desire. There are 2 very important things to note here :

1. / These headers need their NAMES: shown unlike the first three variables in the mail command. The header names are CaSe SeNsItIvE. Use per example.
2. / Each header is ended with the Return and Newline characters. \r\n There are no spaces between each header.


For better organization, these extra headers can be declared in a variable string like our previous examples.

<?php
$to = "";
$subject = "My email test.";
$message = "Hello, how are you?";
$headers = "From: \r\n";
$headers .= "Reply-To: \r\n";
$headers .= "Return-Path: \r\n";
$headers .= "CC: \r\n";
$headers .= "BCC: \r\n";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>

The $headers variable could have been typed out into one long string, but that is a bit much when it comes to editing and viewability. Instead our example shows each one seperated and the .= combines them together. “

http://cisweb.bristol.mass.edu/~pgrocer/mail/emailchk.php

<html>

<head<title>email</title</head>

<body>

<?php

$to = "";

$subject = "PHP email";

$body = "PHP is a great language to work with on the web";

$headers = "From: \n";

mail($to,$subject,$body,$headers);

echo "Mail should be sent to $to";

if (@mail($to, $subject, $message))

{

echo ("<p>Mail sent to $to</p>");

}

else

{

echo ("<p>Problem - mail not sent</p>");

}

?>

</body>

</html>

http://www.sitepoint.com/article/advanced-email-php/2/

First of all, if the mail system you configured in your php.ini file rejects a message you try to send (for example, if the 'to' address is not a valid email address), this function will display an error message in the user's browser. Like most PHP functions, however, error messages may be suppressed by preceding the function name with an @ symbol. Combine this with the fact that the mail function returns either true or false depending on whether the email was accepted by the mail sending system, and you have a formula to send email with appropriate error checking:

<?php
if (@mail($to, $subject, $message)) {
echo('<p>Mail sent successfully.</p>');
} else {
echo('<p>Mail could not be sent.</p>');
}
?>

http://cisweb.bristol.mass.edu/~pgrocer/mail/emailchka.php

<html>

<head<title>email</title</head>

<body>

<?php

$to = "";

$subject = "PHP email";

$body = "PHP is a great language to work with on the web!!!";

$headers = "From: \n";

$message = "This is a message.";

mail($to,$subject,$body,$headers);

echo "Mail should be sent to $to";

if (@mail($to, $subject, $message))

{

echo ("<p>Mail sent to $to</p>");

}

else

{

echo ("<p>Problem - mail not sent</p>");

}

?>

</body>

</html>

http://cisweb.bristol.mass.edu/~pgrocer/mail/emailchkerr.php

<html>

<head<title>email</title</head>

<body>

<?php

$to = "pgrocercomcast.net";

$subject = "PHP email problem";

$body = "PHP is a great language to work with on the web";

$headers = "From: \n";

mail($to,$subject,$body,$headers);

if (@mail($to, $subject, $message))

{

echo ("<p>Mail sent to $to</p>");

}

else

{

echo ("<p>Problem - mail not sent</p>");

}

?>

</body>

</html>

http://cisweb.bristol.mass.edu/~pgrocer/mail/emailhtml.php

Note that I tried message in single and double quotes and it worked fine.

<?php

$to = '' . ',';

$to .= '';

$subject = 'Test HTML in email';

$message = '

<html>

<head>

<title>Testing HTML send in email</title>

</head>

<body>

<p>This is a test</p>

<ul>

<li>Item #1</li>

<li>Item #2</li>

<li>Item #3</li>

</ul>

</body>

</html>

';

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: Test <>' . "\r\n";

$headers .= 'From: Me <>' . "\r\n";

$headers .= 'Cc: Copy<>' . "\r\n";

mail($to, $subject, $message, $headers);

echo "Mail sent to $to";

?>

http://cisweb.bristol.mass.edu/~pgrocer/mail/emailcolor.php

<?php

$to = '' . ',';

$to .= '';

$subject = 'Test HTML in email';

$message = '

<html>

<head>

<title>Testing HTML send in email</title>

</head>

<body bgcolor = "red">

<p>This is a test</p>

<ul>

<li>Item #1</li>

<li>Item #2</li>

<li>Item #3</li>

</ul>

</body>

</html>

';

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: Test <>' . "\r\n";

$headers .= 'From: Me <>' . "\r\n";

$headers .= 'Cc: Copy<>' . "\r\n";

mail($to, $subject, $message, $headers);

echo "Mail sent to $to";

?>

Note that some email does not support color – yahoo does not while my home account does.

http://cisweb.bristol.mass.edu/~pgrocer/mail/emailcolorcss.php

<?php

$to = '' . ',';

$to .= '';

$subject = 'Test HTML in email';

$message = '

<html>

<head>

<title>Testing HTML send in email</title>

<style type="text/css">

body {

background-color: beige;

color: green;

}

</style>

</head>

<body>

<p>This is a test</font</p>

<ul>

<li>Item #1</li>

<li>Item #2</li>

<li>Item #3</li>

</ul>

</body>

</html>

';

$headers = 'MIME-Version: 1.0' . "\r\n";

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= 'To: Test <>' . "\r\n";

$headers .= 'From: Me <>' . "\r\n";

$headers .= 'Cc: Copy<>' . "\r\n";

mail($to, $subject, $message, $headers);

echo "Mail sent to $to";

?>

http://cisweb.bristol.mass.edu/~pgrocer/mail/emailhtmlimg.php

<?php

$to = "" . ",";

$to .= "";

$subject = "Test email using HTML";

$words = "

<html>

<head>

<title>Testing HTML send in email</title>

</head>

<body>

<p>This is a test of to etc</p>

<ul>

<li>Item #1</li>

<li>Item #2</li>

<li>Item #3</li>

</ul>

</body>

</html>

";

$msgPic= '<img src="http://www.pgrocer.net/Cis44/XHTML/images/CISa.gif">';

$message = $msgPic . $words;

$headers = "MIME-Version: 1.0" . "\r\n";

$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

$headers .= "To: Test <>" . "\r\n";

$headers .= "From: Me <>" . "\r\n";

$headers .= "Cc: " . "\r\n";

mail($to, $subject, $message, $headers);

echo "Mail sent to $to";

?>

http://cisweb.bristol.mass.edu/~pgrocer/mail/datatomail.html

<html>

<head<title>Hello with variable</title</head>

<body>

<h3>This is the form</h3>

<form action="emailhtmlimgdata.php" method="get">

Name: <input type="text" name="stuname"<br>

Grade: <input type="text" name="grade"<br<br>

<input type="submit" value="SUBMIT">

</form>

</body>

</html>

http://cisweb.bristol.mass.edu/~pgrocer/mail/emailhtmlimgdata.php

<?php

$stuname = $_REQUEST["stuname"];

$grade = $_REQUEST["grade"];

$to = "" . ",";

$to .= "";

$subject = "Test HTML in email";

$words = "

<html>

<head>

<title>Testing HTML send in email</title>

</head>

<body>

<p>This is a test using double quotes</p>

<ul>

<li>Item #1</li>

<li>Item #2</li>

<li>Item #3</li>

</ul>

</body>

</html>

";

$msgPic= '<img src="http://www.pgrocer.net/Cis44/XHTML/images/CISa.gif">';

$message = $words . $msgPic;

$message .= "\nStudentName: " . $stuname;

$message .= "\nGrade: " . $grade;

$headers = "MIME-Version: 1.0" . "\r\n";

$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

$headers .= "To: Test <>" . "\r\n";

$headers .= "From: Me <>" . "\r\n";

$headers .= "Cc: Copy<>" . "\r\n";

mail($to, $subject, $message, $headers);

echo "Mail sent to $to";

?>