PDA

View Full Version : mail()



Jam-ez
02-12-2008, 06:08 PM
Hi,

I get this error when using the mail() function;

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 \\nas-001\winspace002\10-didehvar.com\www\lq.php on line 168

Code;


<?php

if (!$_POST['submit'])
{

echo("<form action='' method='post'>
Your Name: <br />
<input type='text' name='name' size='20' />
<br /><br />
Your Query: <br />
<textarea name='query' cols='20' rows='5'></textarea>
<br /><br />
<input type='submit' value='Submit Form' /></form>");

$headers .= 'To: Me <>' . "\r\n";
$headers .= 'From: Contact Form From ' . "\r\n";

$name = $_POST['name'];
$query = $_POST['query'];

$to = "";
$subject = "Contact Form - $name";

mail($to, $subject, $query, $headers);
}
else
{
die("Script failed.");
}

?>

Regards,
James.

Excellent2
02-12-2008, 06:12 PM
Try:


<?php

if (!$_POST['submit'])
{

echo("<form action='' method='post'>
Your Name: <br />
<input type='text' name='name' size='20' />
<br /><br />
Your Query: <br />
<textarea name='query' cols='20' rows='5'></textarea>
<br /><br />
<input type='submit' value='Submit Form' /></form>");

$headers .= 'To: Me <>' . "\r\n";
$headers .= 'From: Contact Form From Didehvar.com' . "\r\n";

$name = $_POST['name'];
$query = $_POST['query'];

$to = "";
$subject = "Contact Form - $name";

mail("$to", $subject, $query, $headers);
}
else
{
die("Script failed.");
}

?>

Jam-ez
02-12-2008, 06:14 PM
Try:


find above.

Nope, still get the same error. +Rep for trying, :)
Edit: Must spread.

Excellent2
02-12-2008, 06:17 PM
Forgot to read the error, oops. It's a problem with your localhost so it says, not sure about that then :P

Jam-ez
02-12-2008, 06:20 PM
Forgot to read the error, oops. It's a problem with your localhost so it says, not sure about that then :P

Yeah, but its actually on a website. I've been looking around and its something to do with php.ini (obviously?).

Er, what exactly would I fill this in with;
Source(http://uk3.php.net/mail)

ini_set('sendmail_from', '[email protected]');

Tomm
02-12-2008, 06:30 PM
Contact your host as they'll need to make adjustments in the PHP configuration in order for the mail function to work. Unless you want to set the SMTP server manually yourself...

Calon
02-12-2008, 06:30 PM
Verify that the server you're using has mail extensions, most likely if you're using XAMPP then it's un-likely that you'll have mail extensions too

I can't help noticing that your website appears to be a cPanel account on my server, but i I whois it it's hosted somewhere else.

Jam-ez
02-12-2008, 06:36 PM
No cPanel, just an account + hosting manager.

I suppose I'll have to get in contact then if I have no other options.

iUnknown
03-12-2008, 06:54 PM
Either PHP isn't configured correctly to work with mail/is purposely not configured correctly to work with mail or your host's SMTP is down.

Eitherway, you should contact them, it's nothing to do with your code.

Jam-ez
03-12-2008, 07:47 PM
Either PHP isn't configured correctly to work with mail/is purposely not configured correctly to work with mail or your host's SMTP is down.

Eitherway, you should contact them, it's nothing to do with your code.

I just worked round it, using the fwrite function, who needs email spam?

Want to hide these adverts? Register an account for free!