2015-10-05 75 views
4

我有與phpmailer來到它使用STMPHTML形式的接觸在Azure上託管網絡應用

的代碼是設置這樣直接從解壓一個基本的HTML模板。

<?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 = '[email protected]'; 

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上。

我想要做的另一件事是設置office 365使用他們的API的聯繫表格。有一些javascript代碼,但authContext = new O365Auth.Context();未被識別。

我們只需要一種方式來填寫一個基本的聯繫表格,並通過電子郵件發送到我們的[email protected]我已經用完了這個想法。不管怎麼樣,但我是新來的天青,我卡住了。

回答

2

不確定是否需要與其他SMTP服務器集成,但是可以使用SendGrid完成此任務,並且它最多可以釋放25k條消息。只需從門戶瀏覽Azure Marketplace並將其添加到Azure訂閱。

https://azure.microsoft.com/en-us/marketplace/partners/sendgrid/sendgrid-azure/

使用PHP的整合是非常簡單的。他們建議他們的PHP庫,但你可以使用捲曲這個工作:

<?php 

$url = 'https://api.sendgrid.com/'; 
$user = 'USERNAME'; 
$pass = 'PASSWORD'; 

$params = array(
    'api_user' => $user, 
    'api_key' => $pass, 
    'to'  => '[email protected]', 
    'subject' => 'testing from curl', 
    'html'  => 'testing body', 
    'text'  => 'testing body', 
    'from'  => '[email protected]', 
); 


$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); 

?> 

https://sendgrid.com/docs/Integrate/Code_Examples/php.html

+0

我創建一個SendGrid應用程序現在,謝謝!你知道是否有一個與此類似的Office 365擴展? – teachtyler

+0

Microsoft不建議將Office 365用於應用程序,但它的工作限制爲30封電子郵件/分鐘或10k /天。首先需要在Office 365中設置幾件事情。看到這裏https://technet.microsoft.com/en-us/library/dn554323(v=exchg.150).aspx。還發現這個關於連接到Office 365的錯誤線索,可能與您的情況類似。 –