I had a quick look at SwiftMailer and confused myself entirely as I am not 100% if it would be the best solution for me.
I have some silly questions which I think would give me a better idea.
1. Will Swiftmailer provide me with the ability to create e-mails and send them out so that people using old mail clients/web mail programs that will only accept text and people using slightly newer mail clients using HTML?. I found the following example for use with PHP but I could not get it working correctly. I received an email but i was expecting one line of "Hello World!!! This is simple text email message." but i ended up receiving both.
Will Swiftmailer make this any easier without causing me more problem further down the line?
2. Is it a fairly straight forward process to install this onto a hosted server via Cpanel?
Thank you everyone.
wedmonds
Code: Select all
<?php
//define the receiver of the email
$to = 'example@example.com';
//define the subject of the email
$subject = 'Multipart E-Mail Test';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: wayneedmonds@btinternet.com\r\n Reply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>