I made a PHP mailer but it's not working anymore. It used to work but i changed nothing. It doesnt send the email. I filled in all the neccesary information for it to work but it doesnt. I know im not quite clear with my problem that because i dont know what the problem is and im not really good if it comes to PHP.
Here's the code.
This is the INDEX.PHP
<?php
session_start();
require_once 'helpers/security.php';
$errors = isset($_SESSION['errors']) ? $_SESSION['errors'] : [];
$fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : [];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact form</title>
<link rel="stylesheet" href="css/style.css"/>
<script src="js/test.js"></script>
</head>
<body>
<div class="contact">
<?php if(!empty($errors)): ?>
<div class="panel">
<ul>
<li>
<?php echo implode('</li><li>', $errors); ?>
</li>
</ul>
</div>
<?php endif; ?>
<form action="contact.php" method="post">
<label>
Your name*
<input type="text" name="name" autocomplete="off" <?php echo isset($fields['name']) ? 'Value="' . e($fields['name']) . '"' : '' ?>>
</label>
<label>
Your email address *
<input type="email" name="email" autocomplete="off" <?php echo isset($fields['email']) ? 'Value="' . e($fields['email']) . '"' : '' ?>>
</label>
<label>
Your message *
<textarea name="message" rows="8"><?php echo isset($fields['message']) ? e($fields['message']) : '' ?></textarea>
</label>
<input type="submit" value="Send">
<p class="muted">* Means a required field</p>
</form>
</div>
</body>
</html>
<?php
unset($_SESSION['errors']);
unset($_SESSION['fields']);
?>
This is the CONTACT.PHP
<?php
session_start();
require_once "libs/phpmailer/PHPMailerAutoload.php";
$errors = [];
if(isset($_POST['name'], $_POST['email'], $_POST['message'])) {
$fields = [
'name' => $_POST['name'],
'email' => $_POST['email'],
"message" => $_POST['message']
];
foreach($fields as $field => $data) {
if(empty($data)){
$errors[] = 'The ' . $field . ' field is required.';
}
}
// 587 is voor uitgaande email deze is SSL en SMTP.ziggo.nl
// 993 is voor inkomende email deze is TLS en IMAP.ziggo.nl
// 110 is voor inkomende email deze is POP3 en
if(empty($errors)){
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp1.example.com';
$mail->Username = 'example';
$mail->Password = 'secret';
$mail->SMTPSecure = 'tls';
$mail->Port = 69;
$mail->isHTML();
$mail->Subject = 'Contact form submitted';
$mail->Body = 'From: ' . $fields['name'] . ' ('. $fields['email'] .') <p>'. $fields['message'] .'</p>';
$mail->FromName = 'Contact';
$mail->AddAddress('email', 'name');
if($mail->send()){
header('Location: bedankt.php');
die();
} else {
$errors[] = 'Sorry we konden de email niet verzenden, Probeer later nog een keer.';
}
}
} else {
$errors[] = 'Something went wrong.';
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('location: index.php');
I hope you guys can help me with the information i've given here.
If something is missing please say so
UPDATE
The problem has been solved. I had nothing to do with the code but it was an isseu with the host, Thanks for the help!
First: In contact.php are you sure about port 69 and why not 587 ?
if you are using ziggo the $mail->Host must be smtp.ziggo.nl
Uitgaande serverinstellingen
server: smtp.ziggo.nl
serverpoort: 587
Use ssl: type versleuteling: STARTTLS, TLS of SSL
Be carefull with $mail->isSMTP(); that it is true $mail->isSMTP(true);
working example:
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
require $path.'/phpmailer/PHPMailerAutoload.php'; //the downloaded zip with PHPMailerAutoload i have put into a directoru called phpmailer!!
//require 'PHPmailer.php';
$_error = '';
// insert configs
$_smtpAuth = 'true'; //true
$_smtpSecure = 'SSL'; // TLS og SSL
$_smtpHost = 'send.one.com'; //one.com has send.one.com //gmail has smtp.gmail.com
$_smtpPort = '465';
$_smtpUsername = 'xxx#qwerty.com'; //your email address or username
$_smtpPassword = 'xxxXxxxy'; //your password
$mail = new PHPmailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(true); // Set mailer to use SMTP
$mail->Host = $_smtpHost;//$_smtpHost.';smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = $_smtpAuth; // Enable SMTP authentication
$mail->Username = $_smtpUsername; // SMTP username
$mail->Password = $_smtpPassword; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $_smtpPort; // TCP port to connect to
$mail->setFrom('name#yourwebmail.com', 'Mailer');
$mail->addAddress('', ''); // Add a recipient
$mail->addAddress(''); // Name is optional
$mail->addReplyTo('', ''); //$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('name#awebmail.com'); //Recipient The sender of the email
$mail->addBCC('');
$mail->addAttachment(''); // Add attachments
$mail->addAttachment(''); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
date_default_timezone_set('Europe/Berlin');
require("class.phpmailer.php");
$mail = new phpmailer();
$mail->IsSMTP(); // per SMTP verschicken
$mail->Host = "example.com"; // SMTP-Server
$mail->SMTPAuth = true; // SMTP mit Authentifizierung benutzen
$mail->Username = "example"; // SMTP-Benutzername
$mail->Password = "example"; // SMTP-Passwort
$mail->From = "test#example.com";//any address
$mail->FromName = "example";
$mail->AddAddress($to,"");
$mail->IsHTML(true); // als HTML-E-Mail senden
$mail->Subject = "Confirmation mail ";
$mail->Body = "<html><body>Dear example <br/><br/><br/> \nKind regards\n<br/><br/> KM </body></html>";
if(!$mail->Send())
{
echo "error";
}
else
{
echo "send";
}
Related
Sorry for my bad English :(
I got a big problem here, I have html homepage with contact form in there. I would like to have this form send with PHPMailer, when I send a message I get this but without text :/ I see only the sample text like "Here is the subject". Can someone help me please?
here is the phpmailer.php code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.test.de'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MY EMAIL'; // SMTP username
$mail->Password = 'MY PASSWORT!'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('MY EMAIL');
$mail->addAddress('MY EMAIL'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>
MY EMAIL ist just for secure here
And here ist the code from the html contact form:
<!-- Contact Form -->
<div class="row">
<div class="col-md-8 col-md-offset-2">
<form action="phpmailer_new.php" method="POST">
<div class="form-group">
<input type="text" name="mail" class="form-control" placeholder="Email Address">
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Subject">
</div>
<div class="form-group">
<textarea class="form-control" name="text" rows="3" placeholder="Your Message"></textarea>
<button class="btn btn-default" type="submit">Send Message</button>
</div>
</form>
</div>
</div>
<!-- End Contact Form -->
Cheers Yves
You need to add your variables $_POST in your PHPmailer script :
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.test.de'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MY EMAIL'; // SMTP username
$mail->Password = 'MY PASSWORT!'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('MY EMAIL');
$mail->addAddress($_POST['mail']); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['text'];
$mail->send();
//echo 'Message has been sent';
header('Location: http://www.example.com/contact.php');
exit();
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>
I'm trying to get my HTML contact form to work with the PHPMailer, but when I try to send the message, I'm unable to connect to the server:
2017-06-15 10:39:15 SMTP ERROR: Failed to connect to server: (0) 2017-06-15 10:39:15 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I'm trying to connect to the SiteGround SMTP server.
Form code:
<form id="contact" action="mailer.php" method="post">
<div class="left">
<input type="text" placeholder="Name" required="required" name="name"/>
<input type="email" placeholder="Email" required="required" name="email"/>
<input type="text" placeholder="Subject" required="required" name="subject"/>
</div>
<div class="right">
<textarea placeholder="Message" required="required" name="message"></textarea>
</div>
<div class="send-button cl">
<button type="submit" name="submit">Send</button>
</div>
</form>
PHP Code:
//Creating the message
$message =
'Name: '.$_POST['name'].'<br />
Subject: '.$_POST['subject'].'<br />
Email: '.$_POST['email'].'<br />
Message: '.$_POST['message'].'
';
require 'phpmailer/PHPMailerAutoload.php';
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "mail.frankkreutzer.com";
$mail->Port = 465; // 587 | 465
// $mail->IsHTML(true);
// Authentication
$mail->Username = "email#domain.com";
$mail->Password = "password";
// Compose
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = $_POST['subject'];
$mail->MsgHTML($message);
// Send to
$mail->AddAddress("recipient#domain.com"); // Where to send it
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
Just fixed the PHP code:
<?php
require 'phpmailer/PHPMailerAutoload.php';
//Creating the message
$message =
'Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br /><br />
Subject: '.$_POST['subject'].'<br />
Message: '.$_POST['message'].'
';
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // enable SMTP
// $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages
only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // 587 | 465
// $mail->IsHTML(true);
// Authentication
$mail->Username = "example#email.com";
$mail->Password = "password";
// Compose
$mail->setFrom($_POST['email']);
$mail->Subject = $_POST['subject'];
$mail->MsgHTML($message);
// Send to
$mail->AddAddress("example#email.com"); // Where to send it
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent. I'll get back to you as soon as possible!";
}
?>
I made a contactform which send (if filled in) a mail to the email that's in the code. I want a contactform that send a confirmation email to the person that fills in the form AND to the owner of the site. So the customer knows he filled in the form in the site.
If this makes any sense? I dont know how to explain it better.
CODE: Index.php
<?php
session_start();
require_once 'helpers/security.php';
$errors = isset($_SESSION['errors']) ? $_SESSION['errors'] : [];
$fields = isset($_SESSION['fields']) ? $_SESSION['fields'] : [];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact form</title>
<link rel="stylesheet" href="css/style.css"/>
<script src="js/script.js"></script>
</head>
<body>
<div class="contact">
<?php if(!empty($errors)): ?>
<div class="panel">
<ul>
<li>
<?php echo implode('</li><li>', $errors); ?>
</li>
</ul>
</div>
<?php endif; ?>
<form action="contact.php" method="post">
<label>
Your name*
<input type="text" name="name" id="name" autocomplete="off" <?php echo isset($fields['name']) ? 'Value="' . e($fields['name']) . '"' : '' ?>>
</label>
<label>
Your email address *
<input type="email" name="email" id="email" autocomplete="off" <?php echo isset($fields['email']) ? 'Value="' . e($fields['email']) . '"' : '' ?>>
</label>
<label>
Your message *
<textarea name="message" id="contact" rows="8"><?php echo isset($fields['message']) ? e($fields['message']) : '' ?></textarea>
</label>
<input type="submit" value="Send">
<p class="muted">* Means a required field</p>
</form>
</div>
</body>
</html>
<?php
unset($_SESSION['errors']);
unset($_SESSION['fields']);
?>
CODE: contact.php
<?php
session_start();
require_once "libs/phpmailer/PHPMailerAutoload.php";
$errors = [];
if(isset($_POST['name'], $_POST['email'], $_POST['message'])) {
$fields = [
'name' => $_POST['name'],
'email' => $_POST['email'],
"message" => $_POST['message']
];
foreach($fields as $field => $data) {
if(empty($data)){
$errors[] = 'The ' . $field . ' field is required.';
}
}
// 587 is voor uitgaande email deze is SSL en SMTP.ziggo.nl
// 993 is voor inkomende email deze is TLS en IMAP.ziggo.nl
// 110 is voor inkomende email deze is POP3 en
if(empty($errors)){
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->isHTML();
$mail->SMTPDebug = 2;
$mail->Subject = 'Subject';
$mail->Body = 'From: ' . $fields['name'] . ' ('. $fields['email'] .') <p>'. $fields['message'] .'</p>';
$mail->FromName = $fields['name'];
$mail->AddAddress('rainier.laan#home.nl', 'Rainier Laan');
if($mail->send()){
header('Location: bedankt.php');
die();
} else {
echo $mail->ErrorInfo; exit;
}
}
} else {
$errors[] = 'Something went wrong.';
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('location: index.php');
I hope you guys can help me out with this and can provide me with code i can use. If something i said are unclear please say so. This code is without this function that i explained above, This is only with the function that the owner gets a mail not the customer. Rainier laan.
Use below code for contact.php
<?php
session_start();
require_once "libs/phpmailer/PHPMailerAutoload.php";
$errors = [];
if(isset($_POST['name'], $_POST['email'], $_POST['message'])) {
$fields = [
'name' => $_POST['name'],
'email' => $_POST['email'],
"message" => $_POST['message']
];
foreach($fields as $field => $data) {
if(empty($data)){
$errors[] = 'The ' . $field . ' field is required.';
}
}
// 587 is voor uitgaande email deze is SSL en SMTP.ziggo.nl
// 993 is voor inkomende email deze is TLS en IMAP.ziggo.nl
// 110 is voor inkomende email deze is POP3 en
if(empty($errors)){
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->isHTML();
$mail->SMTPDebug = 2;
$mail->Subject = 'Someone filled in your contactform';
$mail->Body = $fields['name'].' filled in your form with the following message: ' .$fields['message'];
$mail->FromName = $fields['name'];
$mail->AddAddress('rainier.laan#home.nl', 'Rainier Laan'); //added mail id of owner
if($mail->send()){
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = '';
$mail->Username = '';
$mail->Password = '';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->isHTML();
$mail->SMTPDebug = 2;
$mail->Subject = 'Confirmation contactform';
$mail->Body = 'Thank you for filling in our form.<br> Message: <p>'. $fields['message'] .'</p>';
$mail->FromName = 'Owner';
$mail->AddAddress($fields['email] , $fields['name]); //added mail id of user
if($mail->send()){
header('Location: bedankt.php');
die();
}
else{
exit;
}
} else {
echo $mail->ErrorInfo; exit;
}
}
} else {
$errors[] = 'Something went wrong.';
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('location: index.php');
I created a simple form on my page and now I tried to add php script to sending email. Unfortunately it does not work. After clicking on the button, I want the user to remain on my side without redirection.
mail_sender.php
<?php
if(isset($_POST['submit'])){
$to = "someone#gmail.com";
$from = $_POST['email'];
$message = " You received the fallowing message:" . "\n\n" . $_POST['message'];
mail($to,$message,$from);
echo "Mail Sent. Thank you, we will contact you shortly.";
}
?>
HTML
<form action="mail_sender.php" method="post">
<textarea id="email" name="email" rows="1" cols="30" placeholder="Type your email"></textarea>
<textarea id="formContent" name="message" rows="6" cols="30" placeholder="Type your message"></textarea>
<input type="submit" id="submit" value="Send">
</form>
First of all name attribute is missing in your submit button. And php mail function is wrong.
It should be:
$subject = "Your subject";
$headers = "From: $from ";
mail($to,$subject,$message,$headers);
instead of:
mail($to,$message,$from);
PHP's default mail() function doesn't work most of the times, especially with GMail. This is because your e-mail needs to be formatted in a special way to be accpeted by Google's mail server. You'll be better off using a mail library like PHPMailer.
Here's how to send an e-mail using PHPMailer from a GMail Account.
$mail = new PHPMailer();
// ---------- adjust these lines ---------------------------------------
$mail->Username = "xxx#gmail.com"; // your GMail user name
$mail->Password = "passwd"; // your GMail Password
$mail->AddAddress("yyy#gmail.com"); // recipients email
$mail->FromName = "Your Name"; // readable name
$mail->Subject = "Subject";
$mail->Body = "Body";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->From = $mail->Username;
//----------------------------------------------------------------------
if(!$mail->Send())
{
echo "mail sent";
}
I tried everything and now i received message SMTP ERROR: Failed to connect to server and SMTP connect() failed
<form action="mail_sender.php" method="post">
<textarea id="email" name="email" rows="1" cols="30" placeholder="Type your email"></textarea>
<textarea id="formContent" name="message" rows="6" cols="30" placeholder="Type your message"></textarea>
<input type="submit" name="submit" id="submit" value="Send">
</form>
PHP
<?php
require "PHPMailer-master/PHPMailerAutoload.php";
$mail = new PHPMailer();
$to = "someone#gmail.com"; // required
$from = $_POST['email'];
$comment =
'Email: '.$from.' <br> />
Message: '.$_POST['message'].' <br> />'
;
$mail->Username = "someone#gmail.com"; // your GMail user name
$mail->Password = "Password"; // your GMail Password
$mail->AddAddress("someone#gmail.com"); // recipients email
$mail->setFrom($_POST['email']);
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->SMTPDebug = 1;
$mail->IsSMTP(); // use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Subject = 'Here is the subject';
//----------------------------------------------------------------------
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
Here is index.html codes;
<form name="contactform" method="POST" action="send.php">
Name: <input type="text" name="ad_soyad" size="25"><br />
Telephone: <input type="text" name="tel" size="25"><br />
E-Mail: <input type="text" name="email" size="25"><br />
Address: <textarea rows="5" name="adres" cols="25"></textarea><br />
Message: <textarea rows="5" name="mesaj" cols="25"></textarea><br />
<input type="submit" name="button" value="Gonder">
</form>
Here is send.php codes:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'blablabla.com';
$mail->SMTPAuth = true;
$mail->Username = 'blablabla.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
if(($ad_soyad=="") or ($tel =="") or ($email=="") or ($mesaj=="")){
echo "<center>Please fill the required fields.<br><a href=index.html>Go back</a></center>";
}
else
{
$mail->setFrom($_POST['email']);
$mail->addAddress('contact#blablabla.com', 'BlaBlaBla');
$mail->isHTML(true);
$mail->Subject='Contact Form Message';
$mail->Body = ($_POST['mesaj']);
$smtp = new SMTP;
//Enable connection-level debug output
$smtp->do_debug = SMTP::DEBUG_CONNECTION;
if(!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent.';
}
}
?>
It works.
But only sends name,email and message.
So, I want to add more field like telephone or address or etc.
but i can not put them into $mail->body when i tried to write telephone and message together
it gives me error:"not configured properly "
I have to use SMTP because my hosting only provides SMTP..
how can i send all datas which form gets from user ,with SMTP?
I don't know if this will solve the issue - I can't understand why it should fail if you add more content to the message body but as you have not shown that I can only guess it was done in such a way as to make invalid markup?
<?php
/* Are these variables defined before this point? */
if( ( $ad_soyad=="" ) or ( $tel =="" ) or ( $email=="" ) or ( $mesaj=="" ) ){
echo "<center>Please fill the required fields.<br><a href=index.html>Go back</a></center>";
} else {
/* only load the libraries if the above variables are not empty */
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'blablabla.com';
$mail->SMTPAuth = true;
$mail->Username = 'blablabla.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
/* some basic filtering of user supplied variables */
$email=filter_input( INPUT_POST, 'email', FILTER_VALIDATE_EMAIL );
$message=filter_input( INPUT_POST, 'mesaj', FILTER_SANITIZE_STRING );
$name=filter_input( INPUT_POST, 'ad_soyad', FILTER_SANITIZE_STRING );
$tel=filter_input( INPUT_POST, 'tel', FILTER_SANITIZE_STRING );
$address=filter_input( INPUT_POST, 'adres', FILTER_SANITIZE_STRING );
/* prepare message components */
$msg=array();
$msg[]="Name:".$name;
$msg[]="Phone:".$tel;
$msg[]="Address:".$address;
$msg[]="Message:".$message;
$mail->setFrom( $email );
$mail->addAddress('contact#blablabla.com', 'BlaBlaBla');
$mail->isHTML(true);
$mail->Subject='Contact Form Message';
$mail->Body = implode( "\r\n", $msg );
$smtp = new SMTP;
//Enable connection-level debug output
$smtp->do_debug = SMTP::DEBUG_CONNECTION;
if( !$mail->send() ) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent.';
}
$mail = $smtp = null;
}
?>