2015-07-20 3 views
0

В настоящее время у меня есть фрагмент PHP-скрипта, который отправляет электронное письмо от введенного пользователем сообщения. Это было указано GMail как спам-электронное письмо, потому что оно подделало электронную почту. Я хотел бы преобразовать свой скрипт так, чтобы он выполнял то же самое, но через SMTP-адрес электронной почты.PHP Mail to SMTP

<?php 
ob_start(); 
include('mplookup.php'); 
ob_end_clean(); 
$email = $_POST['emailfrom']; 
$human = $_POST['human']; 
$text = $_POST['text']; 
$address = $_POST['address']; 
$city = $_POST['city']; 
$footer = '<br><em><strong>Disclaimer: &quot;Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of EG4DEMUK.&nbsp; EG4DEMUK will not accept any liability in respect of defamatory or threatening communication. If you would like to raise a complaint about an email sent using our tool, please contact us at <a href="mailto:[email protected]?subject=Email%20Complaint"></a>&quot;.</strong></em><p>-----------------------------------------------------------</p> 
The ERC is an organisation that brings together Egyptian citizens and movements abroad, irrespective of their political or ideological affiliations. We share in common a belief in the principles of the January 25th Revolution and oppose all aspects of corruption and dictatorship in Egypt. We believe in constitutional legitimacy and work for the establishment of a civil state that reflects the will of the Egyptian people and their freedom in choosing their government.</p>'; 
$postcode = $_POST['postcode']; 
$name = $_POST['flname']; 
$message = $text.$name."<br />".$address."<br />".$city."<br />".$postcode."<br />".$footer; 
$to = ""; 
$subject = 'Sisi\'s visit to the UK: Sent using the ERC\'s Tool '; 
$headers = "From: ".$email."\r\n"; 
$headers .= "Reply-To: ".$email."\r\n"; 
$headers .= "Return-Path: ".$email."\r\n"; 
$headers .= "BCC: \r\n"; 
$headers .= "CC: $email\r\n"; 
$headers .= 'MIME-Version: 1.0' . "\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

?> 
<?php 

if ($_POST['submit'] && $human == '4') 
{ 
    if (mail ($to, $subject, $message, $headers)) { 
     echo '<p>Your message has been sent! Thank you for participating in EG4DEMUK\'s campaign.</p>'; 
    } 
    else 
    { 
     echo '<p>Something went wrong, please go back and try again!</p>'; 
    } 
} 

?> 

У меня нет понятия, как перейти к преобразованию этого в SMTP. Любая помощь приветствуется.

+2

выглядит очень много, как еще один вопрос отправил на 5 часов раньше http://stackoverflow.com/q/31522742/ - да, я знаю ... многие не может этого видеть. Это потому, что он был удален. 99% из них одно и то же, но несколько изменений/изменений, внесенных в этот. Тем не менее, те же адреса электронной почты. –

+0

Это потому, что я еще один доброволец в той же НПО, работающей по тому же проекту – stackoverflow11

+0

, так почему же вопрос был удален? –

ответ

1

Для этого вы можете использовать предварительно написанную библиотеку PHP.

https://github.com/PHPMailer/PHPMailer

страница GitHub включает в себя очень хороший пример сценария, и вы можете просто скопировать уже записанные параметры соответствующих переменных библиотеки.

Например:

$to = "[email protected]"; becomes $mail->addAddress('[email protected]'); 

    $mail->Body = $message; 

т.д.

+0

Привет, я не уверен, как реализовать HTML в моем сообщении с помощью PHPMailer – stackoverflow11

+1

@ stackoverflow11 Просто сохраните свой HTML (например, описанное выше) и задайте тип письма для HTML с помощью $ mail-> isHTML (true). –

+0

Как настроить проверку в конце ($ human = 4)? Благодарю. – stackoverflow11