0

我想知道如何将表单详细信息发送到外部 url 以及电子邮件 ID。我有将表单详细信息发送到电子邮件 ID 的编程经验,但是我的一个客户要求将表单详细信息的副本重定向到 url,就像这样http://someipaddress.com/XDKRT/SalLeadEntWeb.ASP,我的网站是由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?

4

1 回答 1

0

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

<?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();

$url除了for cURL之外,您可能唯一需要更改的是$postFields. 您应该根据远程 URL 期望发送的内容来更改此设置。

希望有帮助。

于 2012-08-01T21:21:45.830 回答