如何在php文件中添加CURL以将表单详细信息发送到电子邮件和外部数据

如何在php文件中添加CURL以将表单详细信息发送到电子邮件和外部数据,php,Php,我想知道如何将表单详细信息发送到外部url以及电子邮件id。我曾有过将表单详细信息发送到电子邮件id的编程经验,但我的一位客户要求将表单详细信息副本重定向到url,如下所示,我的网站由wordpress开发,有人能指导我如何实现吗?,我知道使用CURL我们可以做到这一点,但是在哪里添加CURL呢?我的php操作表单如下所示: <?php ob_start(); ?> <?php $contact_name = $_POST['name']; $contact_email = $

我想知道如何将表单详细信息发送到外部url以及电子邮件id。我曾有过将表单详细信息发送到电子邮件id的编程经验,但我的一位客户要求将表单详细信息副本重定向到url,如下所示,我的网站由wordpress开发,有人能指导我如何实现吗?,我知道使用CURL我们可以做到这一点,但是在哪里添加CURL呢?我的php操作表单如下所示:

<?php ob_start(); ?>
<?php
$contact_name = $_POST['name'];
$contact_email = $_POST['email'];
$contact_phone = $_POST['phone'];
$contact_message = $_POST['message'];

if( $contact_name == true )
{
    $sender = $contact_email;

    $receiver  = 'info@compositedge.com' . ',referral@compositeinvestments.com'; // note the comma

    $client_ip = $_SERVER['REMOTE_ADDR'];

    $email_body = "Name: $contact_name \nEmail: $contact_email \nPhone No: $contact_phone \nMessage: $contact_message \n";  

    $extra = "From: info@compositedge.com\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

    if( mail( $receiver, "Open an Account - Download and Print", $email_body, $extra ) ) 
    {
    //IF SUCCESSFUL, REDIRECT
header("Location: http://www.mydomain.com/?page_id=1112");
    }
    else
    {
        echo "success=no";
    }
}
?>
<?php ob_flush(); ?>


请求在这方面帮助我,在哪里添加CURL?

这是在调用
mail()
之前添加了CURL请求的代码


无法帮助您将卷曲放在何处,但我会先回答一个稍后可能出现的问题。请注意,curl并不是运行php的大多数web服务器的标准配置,例如xampp。您需要找到php.ini文件并删除关于curl的分号以激活它。然后重新启动计算机,或者如果可以的话,只需启动服务器就可以激活itcURL,这在PHP中非常常见。除非您在Windows上,否则php.ini中没有与curl相关的条目。
<?php ob_start();

$contact_name = $_POST['name'];
$contact_email = $_POST['email'];
$contact_phone = $_POST['phone'];
$contact_message = $_POST['message'];

if( !empty($contact_name)) {
    $sender = $contact_email;
    $receiver  = 'info@compositedge.com' . ',referral@compositeinvestments.com'; // note the comma
    $client_ip = $_SERVER['REMOTE_ADDR'];
    $email_body = "Name: $contact_name \nEmail: $contact_email \nPhone No: $contact_phone \nMessage: $contact_message \n";  
    $extra = "From: info@compositedge.com\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();

    // URL for cURL to post to
    $url        = 'http://someipaddress.com/XDKRT/SalLeadEntWeb.ASP';

    // Postfields for cURL to send
    // NOTE: You probably need to change the array keys to what the remote server expects to receive
    $postFields = array('name' => $contact_name,
                        'email' => $contact_email,
                        'phone' => $contact_phone,
                        'message' => $contact_message);

    // initialize curl and options
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);

    // send curl request
    $res = curl_exec($ch);
    curl_close($ch);
    // you can examine $res here to see if the request was successful


    if( mail( $receiver, "Open an Account - Download and Print", $email_body, $extra ) ) {
        // IF SUCCESSFUL, REDIRECT
        header("Location: http://www.mydomain.com/?page_id=1112");
    } else {
        echo "success=no";
    }
}

ob_flush();