Send PHP Email with out mail() function - php

I have a web account on Windows using PHP with Godaddy. Godaddy want their users to use gdform.php when I would rather use some my own custom php script.
Is it possible to send PHP mail with out the mail() function?

http://phpmailer.worxware.com/
http://swiftmailer.org/
Both these are super-powerful mailing classes for PHP. I use PHPMailer to send out 30,000+ emails per day on my company's online application.
Here's the thing though, I have several simple contact forms on small customer websites hosted by GoDaddy that are using php's mail() without fail. They may tell you not to use it, but it's sure working just fine for me....Or perhaps the Windows servers aren't running PHPMail. As an aside, I'm getting as far away from GoDaddy as quickly as possible.....

Try PEAR::Mail with native SMTP. And there are other pure PHP implementations.

Try Zend_Mail, Great features and easy to use, although I've heard stuff about it's numerous bugs but I'm not sure how much those rumors are true.

Related

How to send SMTP emails with PHP without using a 3rd party class

I've been using PHPMailer to send SMTP emails, and also have heard some recommend various other 3rd party classes.
I've always been a surprised and a little disappointed that this functionality is not native in PHP.
Do I still need to use a 3rd party class to do so? If not, how? If so, any idea why it isn't native?
PHP does have a native function mail() to send emails, but it is not very efficient.
From the official PHP documentation -
It is worth noting that the mail() function is not suitable for larger
volumes of email in a loop. This function opens and closes an SMTP
socket for each email, which is not very efficient.
Official PHP docs suggest using PEAR::Mail library for efficient email support. I would rather use PHPmailer or Swift mailer(http://swiftmailer.org/) though as they both have excellent support and also well documented.
If you are using windows the php mail() function will not work unless you have an smtp server installed on your PC. Windows passes the email to the email server which then sends the email if it has access through your firewall. Also note that mail() as documented is not the correct way to send an email. In order to send an email the email message must be composed in a manner resembling the RFC documentation.

Sending Notification Emails in PHP [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Sending Bulk Emails using PHP
Is there a service out there that can handle sending emails constantly through PHP without issue? We're looking to send out 500+ emails a day or more and are worried about using the built in mail functions of PHP.
Any suggestions?
There's nothing inherently wrong with the built-in mail functions, and 500 e-mails a day is almost no load at all. PHP simply executes your configured MTA executable, such as sendmail.
However, I'd recommend using a better mail API such as Swiftmailer. This will enable you to build e-mails with HTML, attachments, and such much easier than trying to generate your own MIME messages.
For larger mail volumes, I would recommend using a 3rd party, such as MailChimp (or one of the many, many others). They're very good at keeping you off blacklists for spam and such.
500 emails/day really isn't that many. You have several options:
Send the mail yourself, from your server. You could use third party libraries to handle the multitude of options. Swiftmailer, PHPMailer etc or roll your own. Sending from your own servers, you will need to manage reverse DNS, SPF records etc and (assuming you're on Linux) will become quite well acquainted with Postfix et al.
Optionally you can use third-party services, such as http://sendgrid.com/ or http://aws.amazon.com/ses/. These are essentially pay-as-you-go mail servers with nice simple APIs. This can help with a lot of the heavy lifting involved in maintaining reliable mail servers. This gets complicated when you're sending thousands of emails per day. Throttling, queueing, load balancing etc.
Another option, if you're doing eMarketing is to use a service such as Mailchimp or Campaign Monitor. These will do all proofing, sending, throttling and reporting for you for a one-time fee.
you can use php's mail() function without any issue. but most of the shared hosting servers do not allow you send large volume emails.. You can use third party SMTP for this..

How can I send mail with PHP's mail() function and MAMP Pro?

I'm developing a website that will utilize PHP's mail() function. I'm running MAMP Pro (primarily because it has the Postfix feature that is supposed to be useful for sending emails). I feel like I've tried everything, but my program still won't send emails. It doesn't even really matter to me that I use mail(). I just want to be able to send emails from my local MAMP Pro webserver so I can test out my website. Any suggestions would be greatly appreciated!
You need to set it up for your ISP.
http://documentation.mamp.info/en/mamp-pro/server/postfix
also
http://blog-en.mamp.info/2009/09/how-to-sending-emails-with-mamp-pro.html
Other than that, I agree with the comments. What is your ISP? What is php telling you? Also, read your logfile for postfix and tell us what it says:
http://blog-en.mamp.info/2010/03/how-to-show-postfix-log-file-of-mamp.html

is there something wrong with using php's native mail function?

i tried googling but sadly i get only documentations (or am i using bad keywords)
anyway
i can see that alot of programmers (even those im working with right now) does not seem to approve to using the php native mail function and resorts to using some other framework like sendmail? swift mailer etc...
i'd like to know why? are there really disadvantages to using the native mail function?
if so how does the mailing frameworkds solve that or how are they better??
There's nothing wrong with it for sending simple plain text emails.
However, once you get into multipart mime emails (say, you want an HTML version or to add an attachment) then you have to build the email yourself, and it can be quite tricky to get all the headers and encoding correct. In this case you're better off using a library.
The PHP manual for function mail mentions that there are some restrictions with the mail function and one of these are that the function opens and closes an SMTP socket for each email. The mail function works good when you just want to send a mail or two.
As far as I'm concerned, all of these problems pale in comparison to the major security problem:
Mail header injection: ( http://en.wikipedia.org/wiki/E-mail_injection , and php specific info: http://www.damonkohler.com/2008/12/email-injection.html )
Whereby a spammer bot spiders your site and, finding a vulnerability in your script that is easy to still have when using the very insecure mail() function, IS ABLE TO SEND EMAIL FROM YOUR SERVER TO AN ARBITRARY LIST OF CONTACTS, essentially turning your script & server into a cog in their spam email machine.
I recommend never using mail() with user input, and in general, just making use of PEAR::mail instead. http://pear.php.net/package/Mail/
Using PHP's mail() function requires a properly configured sendmail or equivalent on the host the program is running. However, the Windows implementation is a bit different. If you don't have your MTA configured properly, you won't be able to successfully send emails from your PHP scripts. Like another commenter said on this thread, PHP manual explicitly states that each call to the mail() function opens and closes a socket. This can cause unnecessary delay in script execution.
Additionally, your development and testing environment may not have a public static IP address. Your IP address might be blacklisted by DNSBL, Gmail, Yahoo! and other popular email service providers.
Your best bet in this situation is to use a properly configured external SMTP server. Chances are your employer has already provided an email account with SMTP access. If you don't have one you can use a Gmail account. Gmail provides SMTP access to all email accounts.
You can write scripts to open a socket connection to the external SMTP server. When there are tried and tested open source libraries for this purpose, why write your own?
Incidentally, I wrote a blog post on the very same subject yesterday: Using SMTP With Zend Framework - Solve Email Delivery Problem
Best regards,

Does the PHP mail() function work if I don't own the MX record

I'm not sure I'm using all the correct terminology here so be forgiving.
I just put up a site with a contact form that sends an email using the PHP mail() function. Simple enough. However the live site doesn't actually send the email, the test site does. So it's not my code.
It's a shared host and we have another site that has the same function that works perfectly, so it's not the server.
The only difference between the two is that the site that doesn't work just has the name server pointing to us and so the MX record never touches our server.
So my question is, could some one please confirm that the mail() function wont work if we don't have the MX record pointing to our server. Thanks
Yes. It will work just fine. I have a PHP script using the mail() function with the MX records set to Google Apps.
If the two scripts are on different hosts (it's a bit unclear from your post), then make sure that the host doesn't block some of the custom headers. I had issues with this when creating my script, but removing all but the From header fixed the problem.
Some hosts (Godaddy is the worst) block your use of sendmail and mail().
I generally use smtp to send emails from my php applications and with PHPMailer it's super easy. Many applications are using older versions of PHPMailer and sometimes updating it can help. It's also easy enough to add quickly to short scripts as well.
Hey guys thanks for the answers, it is really appreciated.
After ignoring the issue for a few months it has come up again, I did however find the answer to my problems.
Firstly, as you answers suggested, PHP and the mail() function were working as expected. The mail was getting sent.
The problem lies when the email is sent, it simply presumes that because its being sent from mydomain.com to *#mydomain.com email that the email itself is hosted on the same server, so it gets sent there instead and ignores the MX record.
OK it's a bit more complicated than that, but that is the general jist.
Edit:
Found a better version of the topic sendmail and MX records when mail server is not on web host.
The mail() function sends mail from the server hosting the script. Since many shared hosting providers host separate mail servers, and because the mail() function doesn't support any sort of authentication, many shared hosting providers block it.
If the site uses SPF, remember to include the sending site in your SPF record. For more info see here.
Yes, you could put in what ever you want in the 'from' field and it would still work.

Categories