[英]Send an email during form submit
Sorry if the title is a bit vague. 对不起,如果标题有点模糊。 What I mean to say is I have a code like below:
我的意思是我有一个如下代码:
<?php
/* ...generate $to, $subject, $msg, $from variables here */
if(isset($_POST['ccbutton_pressed'])) {
if(mail($to, $subject, $msg, $from)){
echo 'Order Sent';
}else{
echo 'Order Sending Error';
}
}?>
<form method='post' action='SOME_URL_TO_POST_TO' >
<!-- some visible input types -->
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<!-- some hidden input types -->
<input type='hidden' name='hiddenfield1' value='1' />
<input type='hidden' name='hiddenfield2' value='2' />
<input type='submit' value='Submit' />
<input type='hidden' name='ccbutton_pressed' value='1'>
</form>
Is there some way I can send an email upon submission? 有什么方法可以在提交时发送电子邮件吗? While taking notes on the following points below:
同时记下以下几点:
Update: Changed code block to explain more information. 更新:更改了代码块以解释更多信息。 This is also not a duplicate because in Send email with PHP from html form on submit with the same script , the 'action' is left blank while I need mine to post to somewhere.
这也不是重复,因为在使用相同脚本提交时使用html表单发送带有PHP的电子邮件时 ,'action'留空,而我需要将其发布到某个地方。
I'd also like to add that I have checked the above article and it doesn't work for me. 我还想补充一点,我已经检查了上面的文章,但这对我不起作用。
<?php
if(isset($_POST['submit'])){
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$toemail="abc@gmail.com";
$subject="Sending Mail";
$message="Firstname:".$fname."<br/>";
$message.="Lastname:".$lname;
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
//sending simple mail
mail($toemail, $subject, $message, $header);
}
?>
<form method='post' action='' >
<!-- some visible input types -->
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<!-- some hidden input types -->
<input type='hidden' name='hiddenfield1' value='1' />
<input type='hidden' name='hiddenfield2' value='2' />
<input type='submit' value='Submit' id="submit" name="submit" />
</form>
Cheers 干杯
You can probably look at these links to help you. 你可以查看这些链接来帮助你。
Send email with PHP from html form on submit with the same script 使用PHP从html表单发送带有相同脚本的电子邮件
How to create an email form that can send email using html 如何创建可以使用html发送电子邮件的电子邮件表单
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.