Şu anda Azure'u bir SMTP sunucusu olarak kullanmaya çalışırken bir sorun yaşıyorum. Gönderdiğinizde bir e-posta gönderecek basit bir iletişim formu oluşturmaya çalışıyorum. PHP kodu basittir ve önceki bir projeden olduğu gibi başka bir sunucuda çalışır, ancak şimdi Microsoft Azure sunucusunu kullanmam gerekiyor ve okuduklarımdan cURL veya bir sendmail API çağrısı kullanmam gerekiyor. Bunu nasıl yapacağımı bilen biri, bunu işe yaramayacak gibi görünüyor. Bu, Microsoft Eğer cURL işe gitmek için kullanmak gerekir ki kod,Windows azure'da cURL ile php çağrısı
// 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);
Bunu hayal sonra görebilirsiniz çok daha kolaydır, ama tam olarak bu cURL kodunda benim php kodu koymak nerde olsun çalışmak için? Şeylerin azure tarafında eksik olduğum başka bir şey var mı? Şimdiye kadar ihtiyacım olan her şeyi gönderdiğim için sendmail'i kurdum. Burada
eğer yardımcı olur benim php kodu zaten olan bazı kötü kodlama uygulamaları görmek istiyor$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>';
}
}
}
bazı ek hata ayıklama bilgilerini almak için 'curl_exec' sonra ekleyin:' (curl_errno ($ oturumu)) { 'Kıvrılma hatası:' echo eğer. curl_error ($ oturum); } '. Bunu sorunuza ekleyin ve bu sorunun çözülüp çözülmeyeceğini görelim. Http://php.net/manual/en/function.curl-errno.php adresinden – Tom
Yardımlarınız için teşekkürler Tom, aslında haftanın başında çalışmayı başardım. Çalışmamı (ve hatalarım) yardım etmek için gösterdiğiniz çabayı takdir etmek için oradaki gönderiye bir cevap koyun :) –