如何为我的网站创建电子邮件联系表单

时间:2022-10-19 21:55:04

I'm looking to create a form on my website where users can enter their email address and a message (however long). Then upon clicking on a submit button, the code, sends the message as an email to my mailbox.

我想在我的网站上创建一个表单,用户可以在其中输入他们的电子邮件地址和消息(无论多长时间)。然后单击提交按钮,代码将邮件作为电子邮件发送到我的邮箱。

I was wondering if someone knew what code i could use. I am using PHP as my server-side language.

我想知道是否有人知道我可以使用什么代码。我使用PHP作为我的服务器端语言。

3 个解决方案

#1


4  

You need to have access to an smtp server somewhere. Assuming you do, use the php mail function to send the mail like so:

您需要在某处访问smtp服务器。假设你这样做,使用php mail函数发送邮件,如下所示:

$Name = "John doe"; //senders name 
$email = "email@adress.com"; //senders e-mail adress 
$recipient = "recipient@emailadress.com"; //recipient 
$mail_body = "The text for the mail..."; //mail body 
$subject = "Subject for receiver"; //subject 
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header);

The smtp server is set in the php.ini file in these two lines:

smtp服务器在这两行中的php.ini文件中设置:

SMTP = servername
smtp_port = 25

More information at w3schools site.

有关w3schools网站的更多信息。

#2


2  

while the above two answers provide a basic email sending suggestion, there's one thing you should consider, the codes are not secure. spammers can inject Cc: codes and send spam using the form. if they do, your smtp provider may ban your account. try a dedicated mailer, like phpmailer

虽然以上两个答案提供了基本的电子邮件发送建议,但您应该考虑一件事,代码不安全。垃圾邮件发送者可以使用表单注入Cc:代码并发送垃圾邮件。如果他们这样做,您的smtp提供商可能会禁止您的帐户。尝试一个专门的邮件程序,如phpmailer

#3


0  

Try to use PHPForms. It is an ultimate web form builder that allows to create professionally looking email forms within just a few minutes. You will only need to create a PHP form by means of an intuitive interface and generate a code that can be easily copied and pasted to any web page.

尝试使用PHPForms。它是一个终极的Web表单构建器,允许在几分钟内创建专业外观的电子邮件表单。您只需通过直观的界面创建PHP表单,并生成可轻松复制并粘贴到任何网页的代码。

#1


4  

You need to have access to an smtp server somewhere. Assuming you do, use the php mail function to send the mail like so:

您需要在某处访问smtp服务器。假设你这样做,使用php mail函数发送邮件,如下所示:

$Name = "John doe"; //senders name 
$email = "email@adress.com"; //senders e-mail adress 
$recipient = "recipient@emailadress.com"; //recipient 
$mail_body = "The text for the mail..."; //mail body 
$subject = "Subject for receiver"; //subject 
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header);

The smtp server is set in the php.ini file in these two lines:

smtp服务器在这两行中的php.ini文件中设置:

SMTP = servername
smtp_port = 25

More information at w3schools site.

有关w3schools网站的更多信息。

#2


2  

while the above two answers provide a basic email sending suggestion, there's one thing you should consider, the codes are not secure. spammers can inject Cc: codes and send spam using the form. if they do, your smtp provider may ban your account. try a dedicated mailer, like phpmailer

虽然以上两个答案提供了基本的电子邮件发送建议,但您应该考虑一件事,代码不安全。垃圾邮件发送者可以使用表单注入Cc:代码并发送垃圾邮件。如果他们这样做,您的smtp提供商可能会禁止您的帐户。尝试一个专门的邮件程序,如phpmailer

#3


0  

Try to use PHPForms. It is an ultimate web form builder that allows to create professionally looking email forms within just a few minutes. You will only need to create a PHP form by means of an intuitive interface and generate a code that can be easily copied and pasted to any web page.

尝试使用PHPForms。它是一个终极的Web表单构建器,允许在几分钟内创建专业外观的电子邮件表单。您只需通过直观的界面创建PHP表单,并生成可轻松复制并粘贴到任何网页的代码。