I have a VPS where I've installed my site files, including the PHP email script that uses the php mail() function inside of the following directory (how my site directory/path is set up):
/var/www/mywebsite.com/html/
*DIRECTORY/PATH STRUCTURE SHOWN IN THE IMAGE BELOW:
https://ibb.co/2SDjb8z
And when I installed Postfix, I've configured it to send email through Amazon SES. Postfix has been installed inside of the following directory:
/etc/postfix/
*DIRECTORY/PATH STRUCTURE SHOWN IN THE IMAGE BELOW:
https://ibb.co/XF1JFvv
The problem that I'm having is that it will send email from the command line when testing that Postfix has been properly installed along with using the Amazon SES SMTP, BUT my php email script DOESN'T connect from my websites folder directory to Postfix.
How do I connect my php email script to Postfix? Do I need to change directories?
Here is the php mail() function script that I'm using below:
<?php
$to = "MyTestEmailAddress#gmail.com";
$subject = "Another Test!";
$txt = "Hello world!";
$headers = "From: MyEmailAddress#gmail.com" . "\r\n" .
"CC: AnotherTestEmailAddress.com";
mail($to,$subject,$txt,$headers);
?>
Note that the above php script, is the in the file called “email1.php” inside of my website folder. I’m just trying to connect it to Postfix which is located in the “/etc/postfix” directory.
When you installed Postfix it should have created a sendmail command line program.
Locate it and set the path to it in php.ini for the sendmail_path option.
sendmail_path string Where the sendmail program can be found, usually
/usr/sbin/sendmail or /usr/lib/sendmail. configure does an honest
attempt of locating this one for you and set a default, but if it
fails, you can set it here.
Systems not using sendmail should set this directive to the sendmail
wrapper/replacement their mail system offers, if any. For example, »
Qmail users can normally set it to /var/qmail/bin/sendmail or
/var/qmail/bin/qmail-inject.
Related
I have spent all the morning searching this on internet trying to find a solution about this.
I have installed wamp server on Windows 8.1 and i'm trying to send some mails with sendmail (http://glob.com.au/sendmail/) and my gmail account
When i configure sendmail to use port nº 465 I always get this error: Socket Error # 10060Connection timed out
If i try to use port nº 587 i get this line on error log: Connection Closed Gracefully. But no email is sent.
This is my sendmail.ini file
[sendmail]
smtp_server=smtp.gmail.com
;I tried both: 587, 465
smtp_port=587
; I tried: "blank, auto ssl, tls, none"
smtp_ssl=
error_logfile=error.log
debug_logfile=debug.log
auth_username=myaccoun#gmail.com
auth_password=mypass
hostname=localhost
And this is php.ini file
[mail function]
smtp_port = 465
sendmail_path="C:\wamp\sendmail\sendmail.exe -t"
mail.add_x_header = On
ssl_module is active on apache, and php uses php_open_ssl and php_socket extension.
Also i tried to use stunnel whitout any success
EDIT 27/01/2014
I set smtp_port = 465 and smtp_ssl=ssl on sendmail.ini. Also, I set that sendmail.exe has to run as a Windows XP SP3 programs. After doing that, when I run sendmail.exe on windows console, it sends the email correctly. However, when wamp tries to send mails i get this error on sendmail's error logs.: Socket Error # 10060Connection timed out.
This is the code I'm using to test sendmail:
<?php
$email = "mymail#gmail.com";
$to = "mymail#gmail.com";
$subject = "Hi!";
$body = "Hi,How are you?";
$headers = 'From: ' .$email . "\r\n".'Reply-To: ' . $email. "\r\n".'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $body, $headers)) echo("<p>Email successfully sent</p>");
else echo("<p>Email delivery failed</p>");
?>
Finally I found the answer.
The problem is that sendmail has to be run as an administrator. This is the solution to help any one on my situation.
Right click on sendmail.exe
Properties
Compatibility
Change the configuration for all users
Execute as Windows XP SP 3
Execute as adminitrator
And save :D
2 days lost in this nonsense :(
As an extension to the accepted answer:
If you are running the send mail function in PHP, a dialog may come up to ask you to run the 'send mail' app as admin. Upon cliking 'Yes' it will show a command prompt dialog and nothing will happen and you page will hang until the command prompt is closed. The mail function will even return "True", but in reality no message was sent.
To solve this issue, do the instructions same as the accepted answer and ALSO run the server (or IDE) as admin, by either:
1) Right clicking the program (e.g. server, ide, command prompt) and clicking "Run as Administer"
2) OR Right click program> properties> compatiblity> Tick execute as admin
For instance if your using the PHP in built server, run the command prompt as admin and start the server as normal using
C:\wamp\bin\php\php5.5.12\php.exe -S localhost:80 -t C:\Users\path\to\rootFolder
Of course change the file paths to suit your needs.
Hope this helps someone!!! Spent ages on this!
The problem is that sendmail has to be run as an administrator. This is the solution to help any one on my situation.
Right click on sendmail.exe
Properties
Compatibility
Change the configuration for all users
Execute as Windows XP SP 3
Execute as adminitrator
if you using gmail you need create new password "Your application-specific passwords"
On Windows 10, I found the only method that worked was to run the Compatibility Troubleshooter.
Right click on sendmail.exe
Click "Properties"
Select the Compatibility tab.
Click "Run Compatibility Troubleshooter".
Let windows fix it automatically.
I have coded a web site from scratch with XHTML, using Windows XP Pro, and this includes a contact form in PHP. The web site is in a XAMPP folder on the C drive and being run under localhost on my computer at home.
I want to test the form by sending an email test message from it to my live email address. I have tried this by changing the SMTP = localhost in the PHP .ini file to my ISP server address, activating the line,
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
and adding a semicolon to the beginning of the line below,
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
I have placed my live email address in the contact form code like so:
<?php
//send email
if(mail('my#emailaddress.net','Contact
form',$msg, 'From:postmaster#localhost')) {
?>
Then I tried another way by placing my email address under the if(POST) function instead:
<?php
if($_POST) {
$fName = $_POST['fName'];
$fEmail = $_POST['fEmail'];
$fComments = $_POST['fComments'];
$fCaptcha = $_POST['fCaptcha'];
$random_string = $_POST['random_string'];
$to = "myemailaddress#myisp.net";
?>
And changed the mail function lower down in the script accordingly:
<?php
//send email
mail($to, $fName, $fEmail, $fComments);
if(mail($to,'Contact form',$msg, 'From:postmaster#localhost')) {
header("Location: ../email-thankyou.htm");
?>
When I clicked on the submit button, it generated an error page from my ISP server the first time, and from the Firefox browser during later attempts, so something is happening, but in looking at my live email account there is no sign of my message arriving.
I also found that the form itself disappeared and I was left with just the background colour of the page, when clicking on the submit button when I tried the second method.
I have searched through Stack Overflow for similar queries, and tried a few suggestions without success.
I am using XAMPP version 3.1.0.3.1.0. Although I am conversant with XHTML coding, I am a complete novice with regards to PHP programming, as this project using PHP is my first effort to get to grips with it, and would really appreciate any help and advice given, particularly as to writing the mail($to, and if(mail($to, out correctly.
I have now found the answer to this question by downloading and installing smtp4dev 2009 on my C drive. With this little program in conjunction with XAMPP, I can now test my contact form and it receives the messages successfully. The only other thing I needed to to was to configure the XAMPP php ini file as follows:
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster#localhost
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
;sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
As far as the earlier problem of the form disappearing when clicking on the Send button, is concerned - part of the script was in the wrong place and after some trial and error in positioning it, this problem was solved.
You want to set up mercury or a local mail server to be able to do this. Mecury comes installed with xampp.
http://www.youtube.com/watch?v=VU4PT7xMSO0
Currently I have a mail server configured (a real one from my ISP) and mail internal and external works on the command line. In PHP only external users work.
For testing I would like to send to internal users only.
( Ideally I would like to set up lots of aliases that point to one user so mail to:
tom#localhost.com, dick#localhost.com, harry#localhost.com end up in /var/mail/johnsmith )
I'd be greatful if someone could help here. I'm hesitant to edit the postfix config files...
On the command line johnsmith#localhost works but not in PHP. It's using cakePHP and I checked the value of $email-addr just before the send ($this->Email->send();) and the value is johnsmith#localhost. I'm not that familiar with cakePHP yet. The var/log/mail shows nothing, only external email addresses.
(server is Suse linux)
You can use the basic mail php function
http://php.net/manual/en/function.mail.php
Under linux, mail php function relies on sendmail, just check that sendmail is properly installed.
In /etc/postfix/main.cf add localhost.com:
mydestination = $myhostname, localhost.$mydomain,localhost,localhost.com
This allows sending on "localuser#localhost.com" via command line. I loaded up a test php mail form script in a browser and it works, sending mail through to /var/mail/localuser.
At the moment it means I have to check each local users /var/mail file. I'm working on the alias. My first attempt at that failed.
I would like to make it available for clients to create emails through a web based interface without me having to go to mercury mail program and add a new user every time. i just need a source or script that will allow my clients to create emails on my wampserver email system.
I'm using MercuryMail as my mail host and i'm currently public with my server but need an email creation script that i can put into a web page. Preferably PHP.
Please help,
Thanks.
1) Open the “php.ini“. You should know where it is located because it depends upon the particular server you’re running.
2) Search for the attribute called “SMTP” in the php.ini file.Generally you can find the line “SMTP=localhost“. change the localhost to the smtp server name of your ISP. And, there is another attribute called “smtp_port” which should be set to 25.I’ve set the following values in my php.ini file.
SMTP = smtp.wlink.com.np
smtp_port = 25
3) Restart the apache server so that PHP modules and attributes will be reloaded.
4) Now try to send the mail using the mail() function ,
mail(“you#yourdomain.com”,”test subject”,”test body”);
you might get the warning like this,
Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\Program Files\xampp\htdocs\testmail.php on line 1
5) Now specify the following headers and try to send the mail again,
$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;
$headers .= ‘From: sender#sender.com’ . “\r\n”;
mail(“you#yourdomain.com”,”test subject”,”test body”,$headers);
Well that’s all, the mail is sent to “you#yourdomain.com” from the localhost.
Note : Some smtp server verifies the email address of the sender so the email address which is in the place of “sender#sender.com” should be a valid and existing email address otherwise mail might not be sent to the “you#yourdomain.com”.
I am a newbie in Web Development an I am currently learning PHP and MySQL. I have read HeadFirst PHP and MySQL, and tried the examples. But The PHP Mail() function doesn't work on my Local Machine. I have tried the script on a web server but nothing happens, the mail isn't sent. Please Help me. I have configured the PHP.INI file to send emails but still the problem persists.
<?php
$to = "me#me.com";
$sub = "hello";
$msg = "Hello, how are you?";
//Mail Function
mail($to,$sub,$msg);
?>
I am using WebMatrix with PHP 5.2 installed. Please help me, I am trying out this one since last 2 hours! I am stuck!
mail() uses 'localhost' to send - it generally assumes it's on Linux.
You will need to aquire a basic SMTP server and run it on windows, OR you may be able to use the SMTP server of your're ISP.
Whichever option, you will need to edit your php.ini, you will find:
[mail function]
; For Win32 only.
;SMTP =
you must set SMTP to the ip/port of a mailserver - again wither run one locally or use your ISP.
EDIT
You could try this approach - I have personally never tried to use GMail for sending: http://www.linuxquestions.org/questions/programming-9/php-pear-mail-packege-support-security-through-ssl-586976/
But The PHP Mail() function doesn't work
Yes it does. The problem is either with how you configured PHP or with the MTA you configured it to use. You'd need to provide details of both for us to understand why mail is not getting sent.
The above answer also is applicable to those who use a simulated local IIS e.g. the WebMatrix on IIS Express users who reside within a corporate network with a SMTP machine available.
To be able to send emails out from within it one needs to edit the PHP.INI file (found typically in \Program Files (x86)\IIS Express\PHP\v5.3) and replace 'localhost' with the SMTP server IP or DNS name.