Reputation: 1
I currently have a piece of PHP script that sends an email from a user inputted email. This was being identified by GMail as a spam email because it spoofed the email. I would like to convert my script so that it does exactly the same things but through an SMTP email.
<?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: "Any views or opinions presented in this email are solely those of the author and do not necessarily represent those of EG4DEMUK. 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>".</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>';
}
}
?>
I have no clue how to proceed in converting this to SMTP. Any help would be much appreciated.
Upvotes: 0
Views: 266
Reputation: 61
You can use a pre-written PHP library for this.
https://github.com/PHPMailer/PHPMailer
The GitHub page includes a very good example script and you can simply copy your already written parameters to the corresponding variables of the library.
For example:
$to = "[email protected]"; becomes $mail->addAddress('[email protected]');
$mail->Body = $message;
etc.
Upvotes: 1