Is there a mail object like aspSmarMail that I can call from a PHP script specifying the ‘server’, ‘senderaddress’, ‘recipient’, etc. sub-properties? For example in MS Visual Foxpro9 I can use this code:
loIP = CREATEOBJECT( "aspSmartMail.SmartMail" )
loIP.server = "mailout.my.domain.com"
loIP.SenderName = "Emailer"
loIP.SenderAddress = "madeupname@No-Reply.com"
loIP.Recipients.Add( "sadmicrowave@gmail.com" )
loIP.Subject = "Emailer Subject"
loIP.ContentType = "text/html"
loIP.Charset = "us-ascii"
loIP.Body = "This is the body of the email"
loIP.SendMail()
basically this will relay the generated email to the ‘mailout.my.domain.com’ mailserver and it will be sent out that way instead of having to install a SMTP MTA on my localhost.
Is there some syntax to allow me to do this?
While it’s kind of possible to make PHP’s built-in
mailfunction communicate with an arbritary SMTP server, doing it sanely is difficult. The best way to work with an SMTP server in PHP would be using a third-party mailing library.SwiftMailer comes highly recommended in these parts, but PHPMailer and PEAR’s Mail package are also capable of communicating directly with an SMTP server.
Check out SwiftMailer’s documentation on sending via SMTP and the way it assembles messages for a quick howto.