My PHPMailer script
works fine on xampp
local server.But on my website that is located on a apache server isn't working.I think in my apache server doesn't finds the right location of phpMailerAutoload.php
but I'm not sure. I'll be very thankfull if someone can help me with this .
EDIT:When I press the "send" button it displays the error that i set up to display in my PhpMailer script
.(the last else
)
My PHPMailer script
:
<?php
session_start();
require_once '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[]='Il <b>' . $field . '</b> è necessario.';
}
}
if(isset($_POST['tel'])){
$sec_fields=[
'tel'=>$_POST['tel']
];
}
/*------Validation--------*/
if(!empty($_REQUEST['name'])){
$name = $_REQUEST['name'];
if(!preg_match("/^[a-zA-Z'-]+$/",$name)){
$errors[]='Il <b>nome</b> non è valido.';
}
}
if(!empty($_REQUEST['email'])){
$email = $_REQUEST['email'];
$valid = filter_var($email, FILTER_VALIDATE_EMAIL);
if($valid == false){
$errors[]='L\'indirizzo <b>email</b> non è valido.';
}
}
/*------Creating PHPMailer Class-------*/
if(empty($errors)) {
$m= new PHPMailer;
$m -> isSMTP();
$m -> SMTPAuth = true;
$m->Host = 'wolf.dnshigh.com';
$m->Username = 'email@danadesign.it';
$m->Password = 'password';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->isHTML();
$m->Subject = 'Avete ricevuto un nuovo messaggio .' ;
$m->Body =' Inviato da : ' . $fields['name'] . ' (' .$fields['email'] . ') <br><br> <p>' . $fields['message'] . '<br><br> </p> <p>Telefono: ' . $sec_fields['tel'] . '</p>' ;
$m->FromName = 'DanaDesign Mail';
$m->AddAddress ('MyinboxEmail@yahoo.it', 'My name');
/*-----Sending Email------*/
if ($m->send()) {
header('Location: redirect.html');
die();
} else {
$errors[]='Siamo spiacenti,non siamo riusciti a inviare il messaggio.Si prega di riprovare più tardi.';
}
}
} else {
$errors[]='Qualcosa è andato storto.';
}
header('Location: contact.php');
$_SESSION['errors']= $errors;
$_SESSION['fields']= $fields;
$_SESSION['sec_fields']= $sec_fields;
?>
And my contact form:
<section>
<h2>Write us a message</h2>
<div class="contact">
<?php if(!empty($errors)): ?>
<div class="panel">
<ul><li> <?php echo implode('</li><li> ',$errors); ?> </li></ul>
</div>
<?php endif; ?>
<form method="post" action="contact-script.php">
<label>
<img src="img/person.png" alt="Person Icon"> Nome*
<input type="text" name="name" autocomplete="off" <?php echo isset($fields['name']) ? 'value="' . e($fields['name']) . '"' : '' ?> />
</label>
<label>
<img src="img/telephone.png" alt="Telephone Icon"> Telefono
<input type="text" name="tel" autocomplete="off" <?php echo isset($sec_fields['tel']) ? 'value="' . e($sec_fields['tel']) . '"' : '' ?> />
</label>
<label>
<img src="img/mail.png" alt="Mail Icon">Indirizzo email*
<input type="text" name="email" autocomplete="off" <?php echo isset($fields['email']) ? 'value="' . e($fields['email']) . '"' : '' ?> />
</label>
<label>
<img src="img/message.png" alt="Message Icon">Messaggio*
<textarea name="message" cols="20" rows="2"> <?php echo isset($fields['message']) ? e($fields['message']) : '' ?> </textarea>
</label>
<input type="submit" value="Invia" />
</form>
</div>
</section>
Some text is in Italian language , I'm sorry about that.