Send e-mails with PHP Print

  • 88

Here are a few diffrent ways to send an email with php. This is a very simple php mail script, you can use a mail funtion then you dont have to retype the email code the whole time or you can phpMailer that you can authenticate with an email address.

Plain Text Email:
01.<title>Plain text email</title>
02. 
03. 
04.if (isset($_POST['submit'])) {
05.$email_to = $_POST['RecipientEmail'];
06.$subject = $_POST['Subject'];
07.$headers = "FROM: MComm Test "."";
08.$headers .= "Reply-To: MComm "."";
09.$headers  .= "MIME-Version: 1.0"."";
10.$headers  .= "Content-type: text/plain; charset=iso-8859-1"."";
11.$mail_body = $_POST['emailbody'];
12. 
13.//check if the mail has been sent
14.if (mail($email_to, $subject, $body, $headers) ) {
15.echo "Email sent";
16.} else {
17.echo "Email could not be sent";
18.}
19.}
20.<form name="htmlemail" method="post" action="">
21.<input kl_virtual_keyboard_secure_input="on" name="RecipientEmail" type="text">
22.<textarea name="emailbody" rows="5" cols="45"></textarea>
23.<input kl_virtual_keyboard_secure_input="on" name="Subject" type="text">
24.<input name="submit" value="Send" type="submit">
25.</form>
26. 
27. 
HTML Email:
01.<title>Plain text email</title>
02. 
03. 
04.if (isset($_POST['submit'])) {
05.$email_to = $_POST['RecipientEmail'];
06.$subject = $_POST['Subject'];
07.$headers = "FROM: MComm Test "."";
08.$headers .= "Reply-To: MComm "."";
09.$headers  .= "MIME-Version: 1.0"."";
10.$headers  .= "Content-type: text/html; charset=iso-8859-1"."";
11.$mail_body = $_POST['emailbody'];
12. 
13.//check if the mail has been sent
14.if (mail($email_to, $subject, $body, $headers) ) {
15.echo "Email sent";
16.} else {
17.echo "Email could not be sent";
18.}
19.}
20.<form name="htmlemail" method="post" action="">
21.<input kl_virtual_keyboard_secure_input="on" name="RecipientEmail" type="text">
22.<textarea name="emailbody" rows="5" cols="45"></textarea>
23.<input kl_virtual_keyboard_secure_input="on" name="Subject" type="text">
24.<input name="submit" value="Send" type="submit">
25.</form>

Was this answer helpful?

« Back