Send Mail Using Amazon EC2 Instance - php

I am using Amazon EC2 Instance for one of my project, I have installed LAMP on linux server and now while I am trying to send email using simple function it is not sending email also is not giving any error for that.
Things I have done so far.
Created SES account.
Used simple mail function.
Enabled port 25 in security groups.

I solved this issue just by installing sendmail in my instance. Just run bellow command in your terminal
sudo apt-get install sendmail
That worked for me

If you are using a amazon ec2 ami/linux distro use "sudo yum install sendmail" while in SSH

Although your problem relates to Sendmail have you tried following Amazons Documentation?
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-smtp-app.html
This uses postfix but it seems like a better alternative and there's help readily available for it.
You also can use SMTP as Amazon SES supports this:
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-smtp.html
I know this doesn't directly answer your question. You might just need to configure the mail settings in php.ini.

If you are using AWS SES you need to make sure you validate the account first:
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html
With the exception of addresses containing labels (see below), you must verify each email address that will be used as a "From" or "Return-Path" address for your messages.
The entire email address is case-sensitive. For example, if you verify sender#example.com, you cannot send emails from sender#EXAMPLE.com unless you verify sender#EXAMPLE.com also. (Domain verification, however, is case-insensitive. For more information, see Verifying Domains in Amazon SES.)
Until you are granted production access to Amazon SES, you must also verify the email address of every recipient except for the recipients provided by the Amazon SES mailbox simulator. For more information about the mailbox simulator, see Testing Amazon SES Email Sending. For more information about production access, see Requesting Production Access to Amazon SES.

Alternatively, instructions mentioned in the following link can be followed. In this method installing postfix, sendmail or any other mail server is not required.
It uses the PHPMailer class to send email through Amazon SES using the SMTP interface.
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-using-smtp-php.html
It took me a whole day to reach this simpler solution.

Related

sendmail not able to send to specific e-mail address

I'm running an EC2 with (bitnami for wordpress) and have sendmail configured.
No matter if using my own php written forms or now contact form 7 plugin for wordpress there is one specific address (the clients mail address) that simply won't receive the mails from the forms.
I tested with multiple addresses of myself and I always get all the mails. As soon as I swith to the clients mail-address though they don't get the form mails, not even in the Spam-Folder.
What could be a potential reason?
I thought maybe the server doens't like the same sender and receiver address as the sending address in contact form 7 is info#website.at and the receiver is info#website.at … but I also changed that and tested, no difference.
here is the log file, but I'm unable to interpret that properly.
You should be very cautious about sending the email directly from an EC2, many email providers will actually block emails that come from the AWS EC2 ranges. This exists to prevent an EC2 host being used to send spam/spoof emails.
Additionally Bitnami mention in there documentation the below.
We recommend using an external SMTP server to send email from EC2 instances, due to AWS limitations on EC2 machines. For PHP applications, read the instructions on how to send emails using Gmail or using Amazon Simple Email Service (SES).
By using an external SMTP server combined with adding a valid SPF record you should be able to reduce the chance of emails not making it through to the client in addition to not being labelled as spam either.

Send email through a contact form wordpress on Amazon ec2 (windows) issue

Do we really need the Amazon SES service to send email through amazon ec2. I am unable to send emails through Wordpress hosted on Amazon ec2(windows).
Have added port 25 in the security group.
i am using Contact form 7 of wordpress
I am running wordpress on amazon ec2 windows instance.
Please help do i need to do anything else?
I am new to Amazon ec2
If you don't have any SMTP server ready then you can simply use default php mail() to send mail from your wordpress website.
Install contact 7 plugin for wordpress, to create forms.
Install Wp-Mail-SMTP plugin to setup mailer config
Add this line in your wp-config file: define('RELOCATE',1);
Install sendmail package in ubuntu machine using: sudo apt-get install sendmail
This works for me for EC2 server of AWS and also resolved could not instantiate mail function error.
You will need some sort of smtp server, probably not one hosted on the instance.
Unlike linux, windows generally doesn't come with an smtp mail server or mail relay pre-installed. You can set up your own, but sending mail directly from an ec2 instance can be problematic with spam filters.
Your best bet is to relay email via SES or another mail service.

Configuration issue when sending email on Mountain Lion using Postfix

I've been stuck on this problem for the whole afternoon and tonight but cannot find an answer. But I believe it's some easy configuration issue on Mountain Lion.
I want to send out email using PHP, and I installed PEAR:Mail package; that all works fine.
But when I try to send email in PHP, it returns me no error; but email not received.
I further dig into the problem, found that I need to properly set up my local postfix mail program. I therefore following these articles to setup:
http://benjaminrojas.net/configuring-postfix-to-send-mail-from-mac-os-x-mountain-lion/#comment-259; when that didn't work, I followed that one instead: http://slashusr.wordpress.com/2012/02/14/enabling-postfix-for-outbound-relay-via-gmail-on-os-x-lion-11/.
The basic steps in the blog post is to teach you how to send out using GMail by doing some settings in /etc/postfix/main.cf
But when I test it in terminal with command:
date | mail -s test <my_email_address>
Nothing happened, except that when I type "mail" again, it prompted me with a new message, telling me this error (part, only what I think to be useful):
: host smtp.gmail.com[209.85.225.108] said: 530-5.5.1
Authentication Required. Learn more at 530 5.5.1
http://support.google.com/mail/bin/answer.py?answer=14257
aa4sm11414435igc.15 (in reply to MAIL FROM command)
--1306515822A0.1347279593/songyy.local
Content-Description: Delivery report
Content-Type: message/delivery-status
I visited the link given in the error message, but it's irrelevant.
I'll very much appreciate if anyone can give me some advice on this.
I want to send out email using PHP, and I installed PEAR:Mail package; that all works fine.
Very well. Then you must have a "mail relay server" address, to whom mails get sent. It is usually supplied by your Internet provider.
You must configure that address into Postfix, as relayhost. No other setting is usually necessary.
The recipe you followed is much more complicated because it entails Postfix connecting to GMail and authenticating as a user, all through TLS/SSL. To do this you must store the username and password to your GMail account (or another account created for that purpose) in the postfix passwd file.
The fact that GMail complains of "Authentication Required" tells us that either you skipped this detail, or you stored the wrong password; so GMail can't go through the email forwarding process.
Note that if you only use plain SMTP, the outbound emails will be sent in the clear (as opposed to GMail use of SSL encryption).
Check out the system logs if you need to see in detail what happened to your mails.
Another thing to watch out, you say:
I specified the file by setting: smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
This file expects to be in a specific format (documented in the file itself). After that, though, you have to convert the file into the hashfile, which is the same filename but .db extension. Some distributions do this automatically, otherwise you need to manually run the postfix utility postmap (or in a pinch, makemap). In your case:
postmap -c /etc/postfix /etc/postfix/sasl_passwd
This will take /etc/postfix/sasl_passwd and hash it into /etc/postfix/sasl_passwd.db, which is the actual file Postfix checks. It is possible that this particular detail was not covered in the tutorial you followed, and Postfix is still checking a .db file which was built from the previous (and empty!) sasl_passwd.
You are quite right that by specifying user, host and pass in PEAR, you are effectively overriding Postfix configuration - I think the Mail package performs so-called direct-to-MX exchange, and thus does not even need Postfix at all.
The log files should be specified in main.conf and are usually /var/log/messages or /var/log/mail(.something).

options for sending email via PHP

I am pretty new with the options of sending email via PHP code. The options available are sendmail, postfix, and PHPMail. If I use sendmail and postfix this means that I have to use PHP's mail function. I don't know about PHPMail. I will be sending email across domains (hotmail, yahoo, gmail, etc). It's an automatic email sent to a user's email after they completed something (say a registration). What do you guys think about this?
I've tried setting up sendmail in my Ubuntu server, but had some difficulties in setting it up. So that's why I am probably looking for more options.
You need a MTA (mail transport agent) on your machine (sendmail, postifx, ...) or you can connect to a mail provider like gmail using SMTP.
PHPMailer might be a good class for sending emails if you're not using any framework.
PHPMailer is on Google Code and GitHub.
You should have a pretty easy time setting up sendmail on ubuntu
http://ubuntuforums.org/showthread.php?t=196112
This gives the basics it takes to get sendmail installed.
If you are running this server from your house or some non-datacenter there is a chance that your ISP is blocking the port numbers you need such as port 25.
Read through that thread and it should give you some good suggestions for issues you may have.

How do I send up debian sendmail to use google Apps smtp to by pass ISP blocking smtp

I have a debian webserver and it is running shopsite and some php programs. Which use sendmail to send out email to customers. So this server only needs to send email out. So how do I setup sendmail to use Google Apps smtp? Because I am getting the following error: sm-mta stat=Deferred: Connection reset by mx4.hotmail.com
If you haven't gotten it set up yet, the easiest way to do it is ditch sendmail, install postfix, and then set up the Google Apps SMTP server as your smarthost. IIRC, the default postfix config has a fully-commented config file, so you just need to read through it, uncomment the smart host line, put in the Google SMTP server, and you're done.
Otherwise, you still need to set up Google Apps as your smarthost. There's a ton of Google-able info on how to do this; see here for instance.
You cannot make Google your MTA, as far as I know.
Try using sSMTP

Categories