Sending Mail From PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
samfredland
Forum Newbie
Posts: 3
Joined: Tue Aug 09, 2011 2:23 pm

Sending Mail From PHP

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Sending Mail From PHP

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
samfredland
Forum Newbie
Posts: 3
Joined: Tue Aug 09, 2011 2:23 pm

Re: Sending Mail From PHP

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Sending Mail From PHP

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
samfredland
Forum Newbie
Posts: 3
Joined: Tue Aug 09, 2011 2:23 pm

Re: Sending Mail From PHP

Post 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.
Post Reply