Sending mail with 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
Mattycattell
Forum Newbie
Posts: 2
Joined: Mon Mar 18, 2013 6:26 am

Sending mail with PHP

Post 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!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Sending mail with PHP

Post 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.
(#10850)
Mattycattell
Forum Newbie
Posts: 2
Joined: Mon Mar 18, 2013 6:26 am

Re: Sending mail with PHP

Post by Mattycattell »

Okay thank you for your help, is there anything you would recommend or would it be worth not be worth the time?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Sending mail with PHP

Post by Christopher »

(#10850)
limrasoftware
Forum Newbie
Posts: 1
Joined: Fri Mar 29, 2013 2:10 pm

Re: Sending mail with PHP

Post by limrasoftware »

Hi.... use PHP Mailer Class with any (gmail, yahoo..) mail account smtp details
Post Reply