I just switched over to swiftmailer and here’s a testing script that I was working on ->
[php]<?php
include_once ‘vendor/swiftmailer/swiftmailer/lib/swift_required.php’;
include ‘config.php’;
$server_name = filter_input(INPUT_SERVER, ‘SERVER_NAME’, FILTER_SANITIZE_URL);
/* Setup swiftmailer using your email server information */
if (filter_input(INPUT_SERVER, ‘SERVER_NAME’, FILTER_SANITIZE_URL) == “localhost”) {
$transport = Swift_SmtpTransport::newInstance(EMAIL_HOST, EMAIL_PORT); // 25 for remote server 587 for localhost:
} else {
$transport = Swift_SmtpTransport::newInstance(EMAIL_HOST, 25);
}
$transport->setUsername(EMAIL_USERNAME);
$transport->setPassword(EMAIL_PASSWORD);
/* Setup To, From, Subject and Message */
$message = Swift_Message::newInstance();
$submit = htmlspecialchars($_POST[‘submit’]);
if (isset($submit) && $submit === “submit”) {
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$subject = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$email_from = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$comments = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
/* Person or people to send email to */
$message->setTo([
'[email protected]'
]);
$message->setSubject($subject); // Subject:
$message->setBody($comments); // Message:
$message->setFrom($email_from, $name); // From and Name:
$mailer = Swift_Mailer::newInstance($transport); // Setting up mailer using transport info that was provided:
$result = $mailer->send($message, $failedRecipients);
if ($result) {
header("Location: email.php");
exit();
} else {
echo "<pre>" . print_r($failedRecipients, 1) . "</pre>";
}
}
?>
Email Demo
<fieldset>
<legend><?php echo (isset($errMessage)) ? $errMessage : 'Contact Details'; ?></legend>
<label for="name" accesskey="U">Your Name</label>
<input name="name" type="text" id="name" placeholder="Enter your name" required="required" />
<label for="email" accesskey="E">Email</label>
<input name="email" type="email" id="email" placeholder="Enter your Email Address" required="required" />
<label for="phone" accesskey="P">Phone <small>(optional)</small></label>
<input name="phone" type="tel" id="phone" size="30" placeholder="Enter your phone number" />
<label for="website" accesskey="W">Website <small>(optional)</small></label>
<input name="website" type="text" id="website" placeholder="Enter your website address" />
</fieldset>
<fieldset>
<legend>Your Comments</legend>
<div class="radioBlock">
<input type="radio" id="radio1" name="reason" value="support" checked>
<label class="radioStyle" for="radio1">support</label>
<input type="radio" id="radio2" name="reason" value="advertise">
<label class="radioStyle" for="radio2">advertise</label>
<input type="radio" id="radio3" name="reason" value="error">
<label class="radioStyle" for="radio3">Report a Bug</label>
</div>
<label class="textBox" for="comments">Comments</label>
<textarea name="comments" id="comments" placeholder="Enter your comments" spellcheck="true" required="required"></textarea>
</fieldset>
<input type="submit" name="submit" value="submit">
</form>
</body>
[/php]
Here’s the emailstyle.css file contents :
[code]* {
box-sizing: border-box;
}
body {
background-color: #aec4de;
padding: 0;
margin: 0;
}
div.header {
display: block;
width: 100%;
max-width: 800px;
height: 150px;
background-color: #ebdb8d;
padding: 0;
margin: 20px auto;
}
div.header h1 {
font-family: “Palatino Linotype”, “Book Antiqua”, Palatino, serif;
font-size: 3.2rem;
line-height: 150px;
color: #2e2e2e;
text-align: center;
}
form#contact {
display: block;
width: 100%;
max-width: 500px;
height: auto;
background-color: antiquewhite;
padding: 20px;
margin: 5px 0 20px 20px;
}
form#contact fieldset {
border: 2px solid #2e2e2e;
padding: 30px;
margin-bottom: 20px;
}
form#contact fieldset legend {
font-family: “Palatino Linotype”, “Book Antiqua”, Palatino, serif;
font-size: 1.4rem;
color: #2e2e2e;
padding: 0 5px;
}
form#contact fieldset label {
float: left;
display: block;
width: 100%;
max-width: 150px;
height: 25px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.02rem;
line-height: 25px;
color: #2e2e2e;
text-align: right;
padding: 0 10px;
}
form#contact fieldset input {
clear: right;
display: block;
width: 100%;
max-width: 200px;
height: 25px;
border: none;
outline: none;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.0rem;
color: #2e2e2e;
padding: 0 5px;
margin-bottom: 10px;
}
form#contact fieldset .radioBlock {
display: block;
width: 100%;
max-width: 100%;
height: auto;
margin: 0 auto;
}
form#contact fieldset input[type=radio] {
display: none;
margin: 10px;
}
form#contact fieldset input[type=radio] + label.radioStyle {
display: inline-block;
width: 33.33333333333%;
height: 45px;
margin: -2px;
text-align: center;
text-transform: capitalize;
cursor: pointer;
color: #fff;
background-color: #000;
border: 2px solid #ffa;
line-height: 45px;
margin: 10px auto 0 auto;
}
form#contact fieldset input[type=radio] + label.radioStyle:hover {
background-color: #aaa;
color: #ffa;
}
form#contact fieldset input[type=radio]:checked + label.radioStyle {
background-image: none;
color: #ffa;
background-color: #aaa;
}
form#contact fieldset label.textBox {
clear: both;
text-align: left;
padding: 0;
margin-top: 20px;
}
form#contact fieldset textArea#comments {
resize: none;
border: none;
outline: none;
clear: both;
display: block;
width: 100%;
max-width: 660px;
height: 300px;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2rem;
padding: 10px;
}
form#contact input[type=submit] {
outline: none;
border: none;
display: block;
width: 100%;
max-width: 120px;
height: 40px;
cursor: pointer;
background-color: #000;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2rem;
color: #fff;
text-transform: capitalize;
margin-left: 340px;
}
form#contact input[type=submit]:hover {
color: #ffa;
background-color: #aaa;
}[/code]
HTH - John