scriptmaster
10/31/2013 - 12:20 PM

gistfile1.txt

<?php
require 'phpmailer/class.phpmailer.php';

if(empty($_POST['email']) || empty($_POST['title']) || empty($_POST['first_name']) || empty($_POST['last_name'])) return;

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP

// $mail->SMTPDebug = 2;

$mail->SMTPSecure = 'tls';                           // Enable encryption, 'ssl' also accepted
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Host = 'smtp.strato.de'; 					// Specify main and backup server
$mail->Username = 'info@mueller-merkle.de';          // SMTP username
$mail->Password = 'M87D86MMI13';					 // SMTP password

$mail->From = 'info@mueller-merkle.de';
$mail->FromName = 'Müller Merkle Immobilien';

$mail->CharSet = 'UTF-8';

if($_POST['lang'] == 'de')
{
    if(!empty($_POST['gender'])) {
        $_POST['gender'] = $_POST['gender'] == 'M'? 'Herr': 'Frau';
    }

    $email_name = $_POST['gender'].' '.$_POST['title'].' '.$_POST['last_name'];
}
else
{
    if(!empty($_POST['gender'])) {
        $_POST['gender'] = $_POST['gender'] == 'M'? 'Mr.': 'Ms.';
    }

    if($_POST['title']=='Dr'||$_POST['title']=='Dr.'||$_POST['title']=='professor'){
        $email_name=$_POST['title'].' '.$_POST['last_name'];
    }
    else{
        $email_name = $_POST['gender'].' '.$_POST['title'].' '.$_POST['last_name'];
    }
}

$mail->addAddress('info@mueller-merkle.de', $email_name);  // Add a recipient
$mail->addReplyTo('info@mueller-merkle.de', 'Müller Merkle Immobilien');

// $mail->WordWrap = 80;                                 // Set word wrap to 80 characters
//$mail->addAttachment('pdf/free_report.pdf', 'free_report.pdf');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

if($_POST['lang'] == 'de')
{
    if($_POST['source']=='1'){
        $mail->Subject = 'Bewertungsanfrage';
        $email_html='email/valuation_form.html';
    }
    else if($_POST['source']=='3'){
        $mail->Subject = 'Objektsuche';
        $email_html='email/property_search_form.html';
    }
    else if($_POST['source']=='4'){
        $mail->Subject = 'Kontaktanfrage';
        $email_html='email/contact_form.html';
    }

}
else
{
    if($_POST['source']=='1'){
        $mail->Subject = 'Valuation-Request';
        $email_html='email/valuation_form.html';
    }
    else if($_POST['source']=='3'){
        $mail->Subject = 'Property search';
        $email_html='email/property_search_form.html';
    }
    else if($_POST['source']=='4'){
        $mail->Subject = 'Contact-Request';
        $email_html='email/contact_form.html';
    }
}

$email_body = str_replace('<span id="name" class="green"></span>', $email_name, file_get_contents($email_html));
$email_body = str_replace('<span id="gender"></span>', $_POST['gender'], $email_body);
$email_body = str_replace('<span id="first_name"></span>', $_POST['first_name'], $email_body);
// Add more here ...

$mail->Body = $email_body;

//$mail->AltBody = str_replace('<name>', $email_name, file_get_contents('email/market_report.txt'));

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit;
}