Page 1 of 1

Sending Mail From PHP

Posted: Tue Aug 09, 2011 2:36 pm
by samfredland
I am trying to use PHP to send email on Windows 7. I have installed xampp. I am running this code:

Code: Select all

<?php
	$result = mail("samfredland@gmail.com", "Test Email", "Hi there, Sam!", "From:sam@localhost");

	if ($result) {
		echo "Success!";
	}
	else
		echo "Failure.";
?>
from both the command line and via Apache embedded in an HTML file.

Here is what I get from the command line:
C:\xampp\php>php hello.php
sendmail: Error during delivery: Socket Error # 10061
Connection refused.
Success!
BTW, I never get the email.

I have configured the php.ini file as follows:

Code: Select all

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = samfredland@gmail.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off

; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "C:\xampp\apache\logs\php_mail.log"
Please let me know if I have left out any necessary information.

Re: Sending Mail From PHP

Posted: Wed Aug 10, 2011 7:50 am
by social_experiment
samfredland wrote:I have installed xampp.
Are you using Mercury that is bundled with xampp? If so, click on the admin button for the mecury module, this will open a window and one of those will indicate the status of mails sending, it will also indicate any errors there might be.

Re: Sending Mail From PHP

Posted: Wed Aug 10, 2011 7:27 pm
by samfredland
I don't know if I am using Mercury. Is this the default when you install xampp? What is sendmail exactly? What is Mercury?

Re: Sending Mail From PHP

Posted: Thu Aug 11, 2011 2:41 am
by social_experiment
samfredland wrote:I don't know if I am using Mercury. Is this the default when you install xampp? What is sendmail exactly? What is Mercury?
Yes it's the default installed along with xampp. Mercury creates a mail server on your localhost so you can send emails with it. Below is something about sendmail but that's as far as my knowledge about it stretches.
On the Internet, sendmail is the most popular UNIX-based implementation of the Simple Mail Transfer Protocol (SMTP) for transmitting e-mail...
When xampp is running, an icon appears in the toolbar near the clock (on Win systems). Click on this icon to bring up the xampp control panel. The last option should be Mercury. If you click on 'install' it will start the mail server so you can send emails. Next to 'install' is the 'admin' button which brings up (what i assume) is an administrative console. This will show any errors that is related to emails you try to send from the localhost.

Re: Sending Mail From PHP

Posted: Thu Aug 11, 2011 7:59 pm
by samfredland
OK, I opened up Mercury/32 and sent myself an email (to my google account) via the GUI. The email never showed up and in Mercury/32 there is no indication of an error at all.