some kinda mail() problem

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
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

some kinda mail() problem

Post by enchance »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I made an email form "contact.php" which makes use of the code below in a separate php file "mail.php"
but I just can't get it to work. I'm kinda new to php.  ;D

Code: Select all

<?
//assign the constants
$agiemail = "email@agi.com";
$aginame = "AGI";
$inittxt = "WEB: ";

//get the values
$sender = $_POST['fName'];
$subject = $_POST['fSubject'];
$email = $_POST['fEmail'];
$phone = $_POST['fPhone'];
$msg = $_POST['fMessage'];
$checkbox = $_POST['fCheckbox'];
$date = date("l, F j, Y"); 
$time = date("h:i A"); 

//*****The error must be somewhere in the code below*****
$header =
		"To: " . $aginame . "<" . $agiemail . ">\n" .
		"Subject: " . $inittext . $subject . "\n" .
		"From: " . $sender . "<" . $email . ">\n" .
		"X-Mailer: PHP 4.x";
		
$message = 
		"\n**This message was sent from the AGI website**\n\n\n" .
		"Sender: " . $sender . "<" . $email . ">\n" .
		"Date: " $date . " " . $time . "\n" .
		"Reply by phone: " . $checkbox . "\n" .
		"Telephone: " . $phone . "\n\n" .
		$subject . "\n" . $msg;
		
//send the mail + error messages
if(mail($agiemail, $subject, $message, $header))
{
	 header('Location: sent.php');
}
else
{
	header('Location: emailnotsent.php');
}
?>
I keep getting the error message in my browser:

Code: Select all

Parse error: syntax error, unexpected T_VARIABLE in D:\xampp\htdocs\agi\_snippets\php\mail.php on line 25
Can you guys tell me what I'm doing wrong? I'm running it on localhost using the latest version of xamp. This is my first time working on php.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

mail () problem still

Post by enchance »

I saw a problem and changed it which kind of fixed it but now I'm getting another problem:

Edited line:

Code: Select all

"Date: " . $date . " " . $time . "\n" .
//forgot the "." before $date
New problem:

Code: Select all

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 D:\xampp\htdocs\agi\_snippets\php\mail.php on line 31

Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\agi\_snippets\php\mail.php:31) in D:\xampp\htdocs\agi\_snippets\php\mail.php on line 37
What could this be?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

enchance wrote:What could this be?
Exactly what the error message is telling you, Do you have a Mail Server running on your server at port 25?
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post by enchance »

Ok, this is gonna sound stupid but how do I check if I have a mail server? I opened php.ini but I can't make heads of anything in it.
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

more info here: http://au.php.net/mail
enchance
Forum Commoner
Posts: 34
Joined: Sat Sep 15, 2007 12:10 pm

Post by enchance »

Thanks for the info. I uploaded it to the server instead of just using localhost and it worked! Thanks a lot people.
Post Reply