John Davidson

php - I'm trying to trigger a cURL response to a form in a single script and am running into a roadblock

0 comments
Message:


I'm trying to create a script that will run a cURL command when a form is submitted and have yet to successfully receive an email. The Courier API will call an email template I've created through courier.com. Any ideas?


<?php
if(isset($_POST['submit'])){

$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "https://api.courier.com/send",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => array(
'header' => 'MY AUTH TOKEN',
'event' => 'personalized-welcome-email',
'recipient' => 'RECIPIENT ID',
'profile' => '{"email":"MY EMAIL ADDRESS"}',
)
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
}

// result sent by the remote server is in $result

?>

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>


My Answer:
PHP is a popular server-side scripting language that is used to create dynamic web pages. It is often used in conjunction with HTML to add functionality to websites, such as processing form data, interacting with databases, and generating dynamic content. PHP stands for Hypertext Preprocessor and is open source, meaning it is freely available for anyone to use and modify.

Rate this post

5 of 5 based on 8217 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us