我目前正在尝试获取脚本,以将表单提交到网站外部的页面,同时还将通过电子邮件将客户给出的答案发送给我。 mail()函数对于邮件工作正常……但是如何获取这些值并将其提交到外部页面呢?
谢谢你的帮助!
最佳答案
如果您将表单提交到脚本,则可以先发送电子邮件,然后使用cURL向外部页面发出HTTP请求,并张贴要发送的值。但是,如果外部站点依赖于用户拥有的任何cookie,则此方法将不起作用,因为该请求是从您的Web服务器发出的。
例如
<?php
//data to post
$data = array( 'name' => 'tom', 'another_form_field'=>'a' );
//external site url (this should be the 'action' of the remote form you are submitting to)
$url = "http://example.com/some/url";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//make curl return the content returned rather than printing it straight out
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if ($result === false) {
//curl error
}
curl_close($curl);
//this is what the webserver sent back when you submitted the form
echo $result;
关于php - 提交表单并使用PHP通过电子邮件发送,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1312438/