Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP Mail Quckie

  • 17-04-2008 12:14PM
    #1
    Registered Users, Registered Users 2 Posts: 3,484 ✭✭✭


    Lads, have php5 running on a windows nt server.

    the asp mail is working fine:
    Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
    objCDOMail.From    = "blah blah"
    objCDOMail.To      = strTo
    objCDOMail.Cc	   = strCc
    objCDOMail.Subject = strSubject
    objCDOMail.Body    = strBody
    objCDOMail.Send
    Set objCDOMail = Nothing
    

    but the php version is crashing the page
    function send_email($to,$msgsubject, $msg){
    	@$CDONTS = new COM("CDONTS.NewMail");
    	@$CDONTS->From = "blah blah"; 
    	@$CDONTS->To = $to; 
    	@$CDONTS->Subject = $msgsubject;
    	@$CDONTS->BodyFormat = 1; 
    	@$CDONTS->MailFormat = 1; 
    	//@$CDONTS->AttachFile("c:\tmp\somefile.txt");
    	@$CDONTS->Body = $msg;
    	@$CDONTS->Send();
    	@$CDONTS->Close();
    	}
    

    can anyone see anything wrong with it?

    I'd prefer to use the simple mail command but won't work on stupid work server!


Comments

  • Registered Users, Registered Users 2 Posts: 6,652 ✭✭✭daymobrew


    I am using the free sendmail for Windows (site down for me atm). It comes with XAMPP for Windows.

    I point it at my hosting SMTP server and include the username/password for the 'from' account.
    I use the PEAR Mail_Mime module to send my emails.
    [PHP]
    include('Mail.php');
    include('Mail/mime.php');

    $to = 'recipient@another-domain.com';
    $textfile = '/path/to/email/body.txt';
    $file = '/path/to/attachment.doc';
    $crlf = "\n";
    $hdrs = array( 'From' => 'from_addr@domain.com', 'Subject' => 'The email subject' );
    $mime = new Mail_mime($crlf);
    // You can sent a string and FALSE instead of a file.
    $mime->setTXTBody($textfile, TRUE);
    // Obviously attaching a file is optional.
    $mime->addAttachment($file);

    //do not ever try to call these lines in reverse order
    $body = $mime->get();
    $hdrs = $mime->headers($hdrs);
    $mail =& Mail::factory('mail');
    $sendresult = $mail->send($to, $hdrs, $body);
    if (PEAR::isError($sendresult))
    print($sendresult->getMessage());
    [/PHP]


Advertisement