联系表格与电子邮件& PHP中的短信

时间:2016-09-10 06:55:41

标签: php forms email sms contact

我只是PHP的初学者,

我创建了一个简单的联系表格的着陆页 - 姓名,电子邮件&电话字段,PHP代码是

<?php
$name = $_POST['contact-form-name'];
$email = $_POST['contact-form-email'];
$message = $_POST['contact-form-message'];

$to = 'name@example.com';
$subject = 'Subject';

$body = "";
$body .= "Name: ";
$body .= $name;
$body .= "\n\n";

$body .= "";
$body .= "Message: ";
$body .= $message;
$body .= "\n";

$headers = 'From: ' .$email . "\r\n";

//$headers = 'From: noreply@domain.com' . "\r\n";

//$body .= "";
//$body .= "Email: ";
//$body .= $email;
//$body .= "\n";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
mail($to, $subject, $body, $headers);
echo '<span id="valid">Your Email was sent!</span>';
}else{
echo '<span id="invalid">Your message cannot be sent.</span>';
}

我们现在想要的只是从同一联系表单中获取短信和电子邮件,

我们使用Textlocal作为我们的短信网关&amp;有API允许使用PHP发送短信,PHP POST中发送短信代码

    <?php
    // Textlocal account details
    $username = 'youremail@address.com';
    $hash = 'Your API hash';

    // Message details
    $numbers = array(918123456789, 918987654321);
    $sender = urlencode('TXTLCL');
    $message = rawurlencode('This is your message');

    $numbers = implode(',', $numbers);

    // Prepare data for POST request
    $data = array('username' => $username, 'hash' => $hash, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

    // Send the POST request with cURL
    $ch = curl_init('http://api.textlocal.in/send/');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    // Process your response here
    echo $response;
?>

需要帮助将两个PHP合并为一个或两者兼有,

这样我们就可以获得电子邮件和电子邮件。 SMS

*请注意联系表单验证已完成custom.js

由于

阿肖克

1 个答案:

答案 0 :(得分:1)

假设两段原始代码都能正常运行并执行它们应该执行的操作,您可以像下面那样嵌套代码,并根据发送电子邮件的成功发送短信。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com?product_id=$1 [NC,OR]
RewriteRule ^(.*)$ https://www.paypal.com/$1 [L,R=301,NC]