i have downloaded a contact script(with file attachment) from net.i am running it in wamp(pc) but when i click submit it shows this error.can you help me with this error
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 C:\wamp\www\contact.php on line 38 Call S
and can you please tell me that whether the below script will work or not if not can you suggest a good contact form with file attachment
<form action="" enctype="multipart/form-data" method="post">
<label for="name">Name:</label><br/>
<input type="text" id="name" name="name" /><br/>
<label for="email">Email address:</label><br/>
<input type="text" id="email" name="email" /><br/>
<label for="topic">Subject:</label><br/>
<input type="text" id="topic" name="topic" /><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<label>Upload a Menu:</label>
<input type="file" name="file" size="20"><br>
<label for="comments">Your comments:</label><br/>
<textarea id="comments" name="comments" rows="5" cols="30"></textarea><br/>
<button name="submit" type="submit">Send</button>
</form>
<?php
if(isset($_POST['submit']))
{
// Pick up the form data and assign it to variables
$name = $_POST['name'];
$email = $_POST['email'];
$topic = $_POST['topic'];
$comments = $_POST['comments'];
开发者_Go百科 // Build the email (replace the address in the $to section with your own)
$to = 'my@email.com';
$subject = "Contact: $topic";
$message = "$name said: $comments";
$headers = "From: $email";
// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);
// Redirect
echo('<br> your mail has been send<br>');
}
?>
There's nothing wrong with the code and switching to a different script won't help.
The problem is that there is no mail server running on your computer with which to send mail.
As Dan Grossman mentioned that your code is fine, and the error you are getting is SMTP settings. I will try to explain how you can correct these settings and set up your localhost to use your gmail (or any other external SMTP server) for sending emails.
First you need to find the php.ini file and set the sendmail_path, something like:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
Find sendmail.ini
in "Sendmail" Folder in your WAMP installation, and add following:
smtp_server=localhost
smtp_port=25
default_domain=gmail.com
auth_username=[yourgmailname]@gmail.com
auth_password=[yourgmailpassword]
Restart your server. Now it should be able to send email.
Your problem lies with the mailing function, not with the submission of the form.
Get help in changing your php.ini
精彩评论