Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 5th, 2006, 03:47 AM
Registered User
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default class SimpleMail

Hi,

Have got the simple mail class working and its great.

I am just having a problem with the "From" part of the email, this is overwritten by the server php.ini file (IIS and Win2K), all the emails come from the admin rather than the email address passed into the class.

I have tested with a simple (not MIME) email and the from field works so it must have something to do with my code.

Here is my code calling the simple mail class, and doesnt set correct From field, I use the simple mail class and havent changed the downloaded code.

function SendMail($strTo, $StrFrom, $StrFromName, $StrSubject, $htmlContent, $txtContent) {
    $postcard = new SimpleMail();

    $postcard->to = $strTo;
    $postcard->from = $StrFrom;
    $postcard->cc = "tim@type3.co.uk";
    //$postcard->bcc = "bccaddress@yourhost.com";
    $postcard->subject = $StrSubject;
    $postcard->body = $txtContent;
    $postcard->htmlbody = $htmlContent;
    $postcard->send_html = TRUE;

    if ($postcard->send()) {
      //echo "Multipart email sent successfully!";
    }
}

and this is the test send mail that works setting the correct from field

$to = "tim@type3.co.uk";
$subject = "ZDNet Developer article";
$msg = "I completely understand SMTP servers now!";
$headers = "From: me@mycompany.com\r\nReply-To: someoneelse@mycompany.com";
mail("$to", "$subject", "$msg", "$headers");
echo "finished!";

Any help muchly appreciated.

Tim

 
Old September 5th, 2006, 07:04 AM
Registered User
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So.... found the issue.

The downloaded source code has a slight bug, when sending HTML and TXT emails it starts the header string again, clearing the FROM field which is set above, ie

line 31 - $this->headers .= "From: " . $this->from . "\r\n";

sets the from header

line 50 - $this->headers = "MIME-Version: 1.0\r\n";

sets the header for MIME emails but start by clearing the string instead of concatenating it, so we just need a .= instead of an =. So line 50 is now

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

and it all works fine

Tim






Similar Threads
Thread Thread Starter Forum Replies Last Post
Class SimpleMail timType3 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 2 July 27th, 2008 05:56 PM
SimpleMail class problems derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 6th, 2006 05:52 AM
Regarding Class Library (.dll) from class file manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:32 AM
class.SimpleMail.php problem mrthis PHP Databases 2 December 28th, 2005 09:30 AM
How to include c# class and vb class in the .vbprj umeshayk VS.NET 2002/2003 2 January 9th, 2004 12:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.