Page 1 of 1

Sending mail with PHP

Posted: Mon Mar 18, 2013 6:46 am
by Mattycattell
Hi there, I am a newby PHP programmer and have only been using it for roughly 2 weeks now,

I have created a contact us page for a project that I am currently doing, (this is not to be used commercially so I have no need for validation although I am aware of its importance). Anyway every time I try to send the E-mail I am getting the response

"Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in G:\phpServer\xampplite\htdocs\Project_Design(Unit4)\Php\comments.php on line 9
Error!"

I am aware of needing to change something within the PHP.ini mail function but i have no idea what to change or what to change anything too. Underneath is the PHP code that I am using to send the mail (For this purpose i have removed my current email of where i wish the email to be sent too although the provider is still google.

PHP Code

Code: Select all

<?php 
	$name = $_POST['name'];
	$email = $_POST['email'];
	$message = $_POST['message'];
	$formcontent="From: $name \n Message: $message";
	$recipient = "myemail@gmail.com";
	$subject = "Contact Form";
	$mailheader = "From: $email \r\n";
	mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
	echo "Thank You!";
?>
Any help on this matter will be greatly appreciated. Thanks in advance!

Re: Sending mail with PHP

Posted: Mon Mar 18, 2013 11:02 am
by Christopher
It looks like you are running PHP as localhost on a Windows system. There is no sendmail or other SMTP server installed/available.

Re: Sending mail with PHP

Posted: Mon Mar 18, 2013 11:42 am
by Mattycattell
Okay thank you for your help, is there anything you would recommend or would it be worth not be worth the time?

Re: Sending mail with PHP

Posted: Mon Mar 18, 2013 5:12 pm
by Christopher

Re: Sending mail with PHP

Posted: Fri Mar 29, 2013 2:17 pm
by limrasoftware
Hi.... use PHP Mailer Class with any (gmail, yahoo..) mail account smtp details