带有文件附件的 php 联系人脚本需要帮助
我从网上下载了一个联系脚本(带有文件附件)。我正在 wamp(pc) 中运行它,但是当我单击“提交”时,它显示此错误。你能帮我解决此错误吗?
警告:mail() [function.mail] :无法连接到“localhost”端口 25 的邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置,或在第 38 行的 C:\wamp\www\contact.php 中使用 ini_set() 打电话给S
,你能告诉我下面的脚本是否有效吗?如果不行,你能建议一个带有文件附件的良好联系表格吗?
<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'];
// Build the email (replace the address in the $to section with your own)
$to = '[email protected]';
$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>');
}
?>
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'];
// Build the email (replace the address in the $to section with your own)
$to = '[email protected]';
$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>');
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
代码没有任何问题,切换到不同的脚本也没有帮助。
问题是您的计算机上没有运行用于发送邮件的邮件服务器。
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.
正如 Dan Grossman 提到的,您的代码很好,您收到的错误是 SMTP 设置。
我将尝试解释如何更正这些设置并设置本地主机以使用 gmail(或任何其他外部 SMTP 服务器)发送电子邮件。
首先,您需要找到 php.ini 文件并设置 sendmail_path,例如:
在 WAMP 安装的“Sendmail”文件夹中查找
sendmail.ini
,然后添加以下内容:重新启动服务器。现在它应该能够发送电子邮件了。
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:
Find
sendmail.ini
in "Sendmail" Folder in your WAMP installation, and add following:Restart your server. Now it should be able to send email.
您的问题在于邮寄功能,而不是表单提交。
获取更改 php.ini 的帮助
Your problem lies with the mailing function, not with the submission of the form.
Get help in changing your php.ini