html Azure 托管网络应用上的联系表
html contact form on azure hosted web app
我有一个基本的 HTML 模板 phpmailer
使用 STMP
解压后代码就是这样设置的。
<?php
session_start();
include("php/simple-php-captcha/simple-php-captcha.php");
include("php/php-mailer/PHPMailerAutoload.php");
// Step 1 - Enter your email address below.
$to = 'you@domain.com';
if(isset($_POST['emailSent'])) {
$subject = $_POST['subject'];
// Step 2 - If you don't want a "captcha" verification, remove that IF.
if (strtolower($_POST["captcha"]) == strtolower($_SESSION['captcha']['code'])) {
$name = $_POST['name'];
$email = $_POST['email'];
// Step 3 - Configure the fields list that you want to receive on the email.
$fields = array(
0 => array(
'text' => 'Name',
'val' => $_POST['name']
),
1 => array(
'text' => 'Email address',
'val' => $_POST['email']
),
2 => array(
'text' => 'Message',
'val' => $_POST['message']
),
3 => array(
'text' => 'Checkboxes',
'val' => implode($_POST['checkboxes'], ", ")
),
4 => array(
'text' => 'Radios',
'val' => $_POST['radios']
)
);
$message = "";
foreach($fields as $field) {
$message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
}
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->SMTPDebug = 0; // Debug Mode
// Step 4 - If you don't receive the email, try to configure the parameters below:
//$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
//$mail->SMTPAuth = true; // Enable SMTP authentication
//$mail->Username = 'username'; // SMTP username
//$mail->Password = 'secret'; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = $email;
$mail->FromName = $_POST['name'];
$mail->AddAddress($to);
$mail->AddReplyTo($email, $name);
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Body = $message;
// Step 5 - If you don't want to attach any files, remove that code below
if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['attachment']['tmp_name'], $_FILES['attachment']['name']);
}
if($mail->Send()) {
$arrResult = array('response'=> 'success');
} else {
$arrResult = array('response'=> 'error', 'error'=> $mail->ErrorInfo);
}
} else {
$arrResult['response'] = 'captchaError';
}
}
?>
设置好每个变量后,包括第 4 步的所有内容。我继续得到 SMTP connect() failed.
即使调试 3。我们的销售电子邮件使用 Outlook。
所以我认为的问题之一是该网站托管在 Azure 上。
我想做的另一件事是使用他们的 API 联系表格设置 office 365。有一些 javascript 代码,但无法识别 authContext = new O365Auth.Context();
。
我们只需要一种方法来填写基本的联系表格,并将其通过电子邮件发送给我们的 sales@email.com
我 运行 没有办法完成这个。没关系,但我是天蓝色的新手,我被困住了。
不确定是否与其他 SMTP 服务器集成,但您可以使用 SendGrid 完成此任务,它最多可免费发送 25k 条消息。只需从门户浏览 Azure 市场并将其添加到 Azure 订阅。
https://azure.microsoft.com/en-us/marketplace/partners/sendgrid/sendgrid-azure/
使用PHP的集成非常简单。他们推荐他们的 PHP 库,但你可以使用 Curl 来完成这项工作:
<?php
$url = 'https://api.sendgrid.com/';
$user = 'USERNAME';
$pass = 'PASSWORD';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => 'example3@sendgrid.com',
'subject' => 'testing from curl',
'html' => 'testing body',
'text' => 'testing body',
'from' => 'example@sendgrid.com',
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
print_r($response);
?>
我有一个基本的 HTML 模板 phpmailer
使用 STMP
解压后代码就是这样设置的。
<?php
session_start();
include("php/simple-php-captcha/simple-php-captcha.php");
include("php/php-mailer/PHPMailerAutoload.php");
// Step 1 - Enter your email address below.
$to = 'you@domain.com';
if(isset($_POST['emailSent'])) {
$subject = $_POST['subject'];
// Step 2 - If you don't want a "captcha" verification, remove that IF.
if (strtolower($_POST["captcha"]) == strtolower($_SESSION['captcha']['code'])) {
$name = $_POST['name'];
$email = $_POST['email'];
// Step 3 - Configure the fields list that you want to receive on the email.
$fields = array(
0 => array(
'text' => 'Name',
'val' => $_POST['name']
),
1 => array(
'text' => 'Email address',
'val' => $_POST['email']
),
2 => array(
'text' => 'Message',
'val' => $_POST['message']
),
3 => array(
'text' => 'Checkboxes',
'val' => implode($_POST['checkboxes'], ", ")
),
4 => array(
'text' => 'Radios',
'val' => $_POST['radios']
)
);
$message = "";
foreach($fields as $field) {
$message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
}
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->SMTPDebug = 0; // Debug Mode
// Step 4 - If you don't receive the email, try to configure the parameters below:
//$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
//$mail->SMTPAuth = true; // Enable SMTP authentication
//$mail->Username = 'username'; // SMTP username
//$mail->Password = 'secret'; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = $email;
$mail->FromName = $_POST['name'];
$mail->AddAddress($to);
$mail->AddReplyTo($email, $name);
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Body = $message;
// Step 5 - If you don't want to attach any files, remove that code below
if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['attachment']['tmp_name'], $_FILES['attachment']['name']);
}
if($mail->Send()) {
$arrResult = array('response'=> 'success');
} else {
$arrResult = array('response'=> 'error', 'error'=> $mail->ErrorInfo);
}
} else {
$arrResult['response'] = 'captchaError';
}
}
?>
设置好每个变量后,包括第 4 步的所有内容。我继续得到 SMTP connect() failed.
即使调试 3。我们的销售电子邮件使用 Outlook。
所以我认为的问题之一是该网站托管在 Azure 上。
我想做的另一件事是使用他们的 API 联系表格设置 office 365。有一些 javascript 代码,但无法识别 authContext = new O365Auth.Context();
。
我们只需要一种方法来填写基本的联系表格,并将其通过电子邮件发送给我们的 sales@email.com
我 运行 没有办法完成这个。没关系,但我是天蓝色的新手,我被困住了。
不确定是否与其他 SMTP 服务器集成,但您可以使用 SendGrid 完成此任务,它最多可免费发送 25k 条消息。只需从门户浏览 Azure 市场并将其添加到 Azure 订阅。
https://azure.microsoft.com/en-us/marketplace/partners/sendgrid/sendgrid-azure/
使用PHP的集成非常简单。他们推荐他们的 PHP 库,但你可以使用 Curl 来完成这项工作:
<?php
$url = 'https://api.sendgrid.com/';
$user = 'USERNAME';
$pass = 'PASSWORD';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => 'example3@sendgrid.com',
'subject' => 'testing from curl',
'html' => 'testing body',
'text' => 'testing body',
'from' => 'example@sendgrid.com',
);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
print_r($response);
?>