現在AzureをSMTPサーバーとして使用しようとすると問題が発生しています。私はあなたが送信したときに電子メールを送信する簡単な連絡フォームを作成しようとしています。 PHPコードはシンプルで、以前のプロジェクトのものと同じように別のサーバー上で動作しますが、Microsoft Azureサーバーを使用する必要があります。また、cURLまたはsendmail API呼び出しを使用する必要があります。私はそれを動作させるように見えないので、誰もこれを行う方法を知っていますか?これは、マイクロソフトでは、カールが仕事を得るために使用する必要があると言うコード、WindowsでcURLを使用したphp呼び出しazure
// 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);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
// print everything out
print_r($response);
私はこれを想像するが、私は見ることができますはるかに簡単ですが、まさに私は、このcURLのコードで私のPHPコードを入れない場所を取得するにはそれは働く?私は物事の青空の側にも欠けているものがありますか?私はすでに自分のアカウントにsendmailをインストールしています。それはいくつかの悪いコーディングプラクティスを見たい
$url = 'https://api.sendgrid.com/';
$user = '[email protected]';
$pass = 'password7';
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => '[email protected]',
'subject' => 'testing from curl',
'html' => 'testing body1',
'text' => 'testing body2',
'from' => '[email protected]',
);
$request = $url.'api/mail.send.json';
if ($_POST["submit"]) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Contact Form';
$to = '[email protected]';
$subject = 'Message from Contact Form ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName || !$errEmail || !$errMessage || !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
いくつかの追加のデバッグ情報を取得するために、あなたの 'curl_exec'後にこれを追加:'場合(curl_errno($セッション)){エコー 'カールエラー:' を。 curl_error($ session); } '。あなたの質問にそれを加えて、この問題を解決できるかどうかを見てみましょう。 http://php.net/manual/en/function.curl-errno.php – Tom
あなたの助けてくれてありがとうTom、私は実際に週の初めにそれを稼働させることができました。あなたの努力(と間違い)を助けるためにあなたの努力を感謝するためにそこに投稿のための答えを入れて: –