Sending Mail using PHP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Sending Mail using PHP

Postby raj_4_PHP » 24. November 2012 16:21

Hi All,

Howz u???

Could u plz lemme know, if sending a mail using PHP requires any server or something like working email system?
I tried simple text mail using php in localhost using below code but, it didn't work:

<?php
$to = "<my frnd'z id>";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "<my id>";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

If it need a server, is there any link to get a free test server?

Thanx in advance! :)
raj_4_PHP
 
Posts: 4
Joined: 31. October 2012 16:55
Operating System: Windows XP

Re: Sending Mail using PHP

Postby JonB » 24. November 2012 18:13

What you need is probably the 'fake sendmail' (Windows replacement for *nix 'sendmail').

Its found in the \xampp\sendmail folder.

Good Luck
:)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Sending Mail using PHP

Postby raj_4_PHP » 25. November 2012 08:13

Hi JonB,

Thanx for your candid help. I found below info in sendmail.ini after reaching the location you mentioned:

# Example for a user configuration file

# Set default values for all following accounts.
defaults
logfile "C:\xampp\sendmail\sendmail.log"

# Mercury
account Mercury
host localhost
from postmaster@localhost
auth off

# A freemail service example
account Hotmail
tls on
tls_certcheck off
host smtp.live.com
from [exampleuser]@hotmail.com
auth on
user [exampleuser]@hotmail.com
password [examplepassword]

# Set a default account
account default : Mercury

----------------------------------------
As I am a complete novice in this, can you please guide me how to implement this in my code?

Thanx in advance! :)
raj_4_PHP
 
Posts: 4
Joined: 31. October 2012 16:55
Operating System: Windows XP

Re: Sending Mail using PHP

Postby JonB » 29. November 2012 04:27

1- First, you will need to configure the sendmail.ini file with the account information for an SMTP server you have rights on.

here are my settings from a running XAMPP 1.7.3 server for one of my blogs -

Code: Select all
# Set default values for all following accounts.
defaults
logfile "\xampp\sendmail\sendmail.log"

# JonB
account JonB
host mail.newnetz.com
from jonb@newnetz.com
auth on
user jonb@newnetz.com
password xxxyyzz

# Set a default account
account default : JonB


2. then you configure PHP to use the 'fake sendmail'

All you have to do with PHP is adjust the {mail function] in php.ini, and the 'mail' functions will be pointed at sendmail. (Be sure to restart Apache)

Code: Select all
[mail function]

sendmail_path = "\xampp\sendmail\sendmail.exe\ -t"

mail.add_x_header = Off


Good Luck
:)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 92 guests