Ive been trying to get my contact form working, but i'm not receiving any emails in my gmail folders (including spam and trash. and also can't track anything through my host).
I've been following this tutorial: http://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form
Need some serious help as i've tried everything!
<?php
$from = $_POST['email'];
$sendTo = 'myemail#gmail.com';
$subject = 'New message from contact form';
$fields = array('name' => 'Name', 'surname' => 'Surname', 'email' => 'Email', 'phone' => 'Phone', 'message' => 'Message');
// array variable name => Text to appear in email
$okMessage = 'Contact form succesfully submitted. Thank you, I will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';
// let's do the sending
try
{
$emailText = "You have new message from contact form\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
mail($sendTo, $subject, $emailText, "From: " . $from);
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
THE HTML FORM
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="messages"></div>
<div class="form-group">
<div class="row">
<div class="col-md-6 col-sm-12">
<label>First name*</label>
<input type="text" id="form-name" name="name" class="form- control" placeholder="Please enter your firstname *" required="required">
</div>
<div class="col-md-6 col-sm-12">
<label>Last name*</label>
<input type="text" name="surname" id="form-surname" class="form-control" placeholder="Please enter your firstname *" required="required">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6 col-sm-12">
<label>Email*</label>
<input type="email" name="email" id="form-email" class="form-control" placeholder="Please enter your firstname *" required="required">
</div>
<div class="col-md-6 col-sm-12">
<label>Phone</label>
<input type="tel" name="phone" id="form-phone" class="form- control" placeholder="Please enter your phone">
</div>
</div>
</div>
<div class="form-group">
<label for="comment">Message*</label>
<textarea class="form-control" rows="7" name="message" id="form-message" default="Type us a message" required="required"></textarea>
</div>
<div class="checkbox">
<label><input type="checkbox" value="">Join mailing list</label>
</div>
<input type="submit" class="btm btn-success btn-send" value="Send message">
<p class="text-muted"><strong>*</strong> These fields are required.</p>
</form>
As many servers don't allow you to send emails in the name of someone whom is not registered, you should create an email on your server that's only for sending you the emails that your users write once they fill the contact form, then you should use a class like PHPMailer to send the email for you.
A simple example showing how to use PHPMailer would be:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.yourserver.here'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#userserver.here'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('user#userserver.here', 'Mailer');
$mail->addAddress('your#email.here', 'You'); // Add a recipient
$mail->addReplyTo('theuser#email.here', 'User that submitted form');
$mail->Subject = 'Subject here';
$mail->Body = 'Write here your message';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
The example is taken from the link I've told you above.
You don't have Mail Delivery error?
Try send email from know host in:
$from = $_POST['email']; (like youremail#gmail.com)
Gmail checks DKIM (posted by) and SPF (signed by) record in DNS server to email host. If email host don't have a DKIM record, email may be not supplied.
More (gmail):
https://support.google.com/mail/answer/180707?hl=en
More (How To Install and Configure DKIM):
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-dkim-with-postfix-on-debian-wheezy
Related
I am building a website that has a php contact form that will send an email on #outlook.com address. Website will be published on ftp server, but till then I published it on this free one https://www.000webhost.com/ so I can test contact form but it is not working. I've read somewhere that php mail() function does not work with smtp so I tried using PHPMailer as I found in some suggestions here (Trying to send email through PHP using an email address that is configured on Microsoft's SMTP servers (#live.com, #outlook.com, etc.)) but it's also not working or maybe I'm not doing it correctly since I don't quite understand it. The code is written without using PHPMailer:
PHP:
<?php
if ($_POST["submit"]) {
if (!$_POST['name']) {
$error="<br />Please enter your name";
}
if (!$_POST['email']) {
$error.="<br />Please enter your email address";
}
if (!$_POST['message']) {
$error.="<br />Please enter a message";
}
if ($_POST['email']!="" AND !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) {
$error.="<br />Please enter a valid email address";
}
if ($error) {
$result='<div class="alert alert-danger"><strong>There were error(s)in your form:</strong>'.$error.'</div>';
} else {
if (mail("mymail#outlook.com", "message from website!", "Name: ".$_POST['name']."Email: ".$_POST['email']."message: ".$_POST['message'])) {
$result='<div class="alert alert-success"><strong>Thank you!</strong> I\'ll be in touch.</div>';
} else {
$result='<div class="alert alert-danger">Sorry, there was an error sending your message. Please try again later.</div>';
}
}
}
?>
HTML:
<div>
<?php echo $result; ?>
<form method="POST" enctype="multipart/form-data ">
<div class="form-group ">
<label><h3>Your name:</h3></label>
<input name="name" type="text " id="exampleInputName" class="form-control" placeholder="Name" value="<?php echo $_POST['name']; ?>">
</div>
<div class="form-group ">
<label><h3>Your e-mail:</h3></label>
<input name="email" type="email " id="exampleInputEmail" class="form-control" placeholder="name#email.com" value="<?php echo $_POST['email']; ?>">
</div>
<div class="form-group ">
<label><h3>Message:</h3></label>
<textarea name="message" class="form-control " rows="5" placeholder="Your message... " value="<?php echo $_POST['message']; ?>"></textarea>
</div>
<div class="col text-right">
<div class="form-group ">
<button class="button" type= "submit" name="submit" value="Submit">send</button>
</div>
</div>
</form>
</div>
Another separate code where I tried using PHPMailer looks like this, which is basically copied from this link getting custom php contact form to send email to exchange 365 account
:
<?php
if ($_POST["submit"]) {
include("PHPMailer-master/class.PHPMailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = false;
$mail->Username = "mymail#outlook.com"; #or do i put my account for webhostapp?
$mail->Password = "my_password_for_outlook";
$mail->From = 'https://webpage.000webhostapp.com/';
$mail->FromName = $_POST['name'];
$mail->AddAddress('mymail#outlook.com');
$mail->IsHTML(true);
$mail->Subject = 'Subject line goes here';
$mail->Body = $_POST['message'];
$mail->AltBody = $_POST['message'];
$mail->Send();
}?>
result after submitting form
I have created a simple html & bootstrap contact form which is backed by PHPMailer class to send an email. The program works perfectly till the sending of email. However, it is not showing the success/failure message on the same page and not clearing the fields also.
The code which I have written for my demo program is below. Please append your solutions to the same code rather making another code of your own.
index.html
<form method="post" action="mail.php" id="contact-form" role="form">
<div class="card-header">
<h2 class="font-weight-bold text-center my-4">Contact us</h2>
<p class="text-center mx-auto mb-5">Do you have any questions? Please do not hesitate to
contact us directly. Our team will come back to you within
a matter of hours to help you.</p>
<div class="alert alert-success" id="success-message"><span>Thank you for contacting us. We will
be in touch
soon.</span></div>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<div class="form-group ">
<label for="name" class="is-required">Name</label>
<input type="text" name="name" id="name" class="form-control" minlength="3"
required>
</div>
</div>
<div class="col-md-6">
<div class="form-group ">
<label for="email" class="is-required">email</label>
<input type="email" name="email" id="email" class="form-control" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="message" class="is-required">Message</label>
<textarea name="message" id="message" rows="2" class="form-control"
required></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="text-center text-md-left">
<input type="hidden" name="action" value="sendEmail" />
<button id="submit-button" name="submit" type="submit" value="Send"
class="btn btn-primary"><span>Send</span></button>
</div>
<div class="status" id="status"></div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="status" id="status"></div>
</div>
</div>
</div>
</form>
jQuery/ajax
<script>
$('form').validate();
$(document).ready(() => {
$('#success-message').hide();
$('form').submit((e) => {
let formData = {
'name': $('#name').val(),
'email': $('#email').val(),
'message': $('#message').val(),
'submit': 1
};
$.ajax({
type: 'POST',
url: 'mail.php',
data: formData,
dataType: 'json',
encode: true
}).done((data) => {
if (data.success) {
$('#success-message').show();
} else {
alert('Something went wrong. Please try again!');
}
});
e.preventDefault();
});
});
</script>
mail.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// header('Content-Type: application/json');
if (isset($_POST['submit'])) {
$name = $_POST['name']; // Sender's name
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
$message = $_POST['message']; // Sender's message
$errorEmpty = false;
$errorEmail = false;
if (empty($name) || empty($email) || empty($message)) {
echo "<span class='alert alert-danger'> Name is required.</span>";
$errorEmpty = true;
}
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "<span class='alert alert-danger'> Please try entering a correct email.</span>";
$errorEmail = true;
}
// Instantiate PHPMailer class
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail#gmail.com'; // SMTP username
$mail->Password = 'mypass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('mymail#gmail.com', 'My Name');
$mail->addAddress($email, $name); // Add a recipient
$body = '<p>Hello <strong> Mr. ' . $name . '</strong> <br /><br /> We have received your enquiry "' .$message. '". <br /> We ensure you that the team is working on it. <br /><br /> Thank you. </p>';
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'We received your query.';
$mail->Body = $body;
// $mail->AltBody = strip_tags($body);
$mail->send();
// echo 'Message has been sent';
} catch (Exception $e) {
echo $e->errorMessage();
echo "Mailer Error: " . $mail->ErrorInfo;
}
} else {
echo "There was an error!";
}
?>
Your any help is highly appreciated. Thanks in advance.
You're not really trying here. You're making an XHR, but not even attempting to return the results in a format that will work with that, and neither are you returning an error code that will trigger your error handler. First of all, you need to set the correct content type:
header('Content-type: application/json');
Then handle errors or valid responses apropriately, giving results in JSON format:
} catch (Exception $e) {
//Some other code may be better, but anything other than 2xx will do for jQuery
http_response_code(400);
echo json_encode(['status' => false, 'errormessage' => $e->errorMessage(), 'errorinfo' => $mail->Errorinfo]);
exit;
}
echo json_encode(['status' => true]);
exit;
Note that if your check for isset($_POST['submit']) fails, you should not say anything (you're currently displaying an error) - it's what will happen when they first load the page.
I was wondering someone could help me out with a best practice to achieve the following.
Please bare in mind I have very little experience with PHP, and am doing something more of a favour for a friend's company (his current developer is travelling and not due back until March).
He's put together 3 basic landing pages (each relevant to an industry), each has the exact same form on. The problem at the moment is the way they work is they all post to the same email address and have the same subject line (they all post to contact.php).
So what I'd like to do is add an IF statement, and perhaps put output a different $subject and $sendTo so they can be unique depending on each form. I've been having a look around and don't really want to have to create a new form and implement that, hopefully, I can just adjust what's here.
Here's contact.php
<?php
// an email address that will be in the From field of the email.
$from = 'Contact form <creative#email.com>';
// an email address that will receive the email with the output of the form
$sendTo = 'Contact form <creative#email.com>';
// subject of the email
$subject = 'Contact form enquiry from the Creative Services Landing Page';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'marketing' => 'Marketing');
// message that will be displayed when everything is OK :)
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';
/*
* LET'S DO THE SENDING
*/
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailText = "You have a new message from your contact form\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
// Send email
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
// if requested by AJAX request return JSON response
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
// else just display the message
else {
echo $responseArray['message'];
}
And here's the HTML
<form class="container" id="contact-form" method="post" action="contact.php" role="form">
<div class="row justify-content-md-center">
<div class="col-12 col-md-5 col-lg-4">
<div class="messages"></div>
</div>
<div class="col-12 col-md-5 col-lg-4">
<div class="form-group">
<input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your firstname *" required="required" data-error="Your first name is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-12 col-md-5 col-lg-4">
<div class="form-group">
<input id="form_lastname" type="text" name="surname" class="form-control" placeholder="Please enter your lastname *" required="required" data-error="Your surname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-12 col-md-5 col-lg-4">
<div class="form-group">
<input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-12 col-md-5 col-lg-4">
<div class="form-group">
<input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your email *" required="required" data-error="A valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-12 col-md-3 col-lg-2">
<button type="submit" class="btn btn--primary">Send</button>
</div>
</div>
</form>
Any help would be hugely appreciated!
You could give to every form a different value via $_GET:
<form class="container" id="contact-form" method="post" action="contact.php?landing_page=1" role="form">
And then depending of $_GET['landing_page'] value set $from, $sendTo and $subject variables:
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'marketing' => 'Marketing');
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';
if (isset($_GET['landing_page']))
{
if ($_GET['landing_page'] == 1)
{
$from = 'Contact form <creative#email.com>';
$sendTo = 'Contact form <creative#email.com>';
$subject = 'Contact form enquiry from the Creative Services Landing Page';
}
elseif($_GET['landing_page'] == 2)
{
$from = 'Contact form <creative#email.com>';
$sendTo = 'Contact form <creative#email.com>';
$subject = 'Contact form enquiry from the Creative Services Landing Page';
}
elseif($_GET['landing_page'] == 3)
{
$from = 'Contact form <creative#email.com>';
$sendTo = 'Contact form <creative#email.com>';
$subject = 'Contact form enquiry from the Creative Services Landing Page';
}
else
{
throw new \Exception('Invalid landing_page value');
}
}
else
{
throw new \Exception('Invalid landing_page value');
}
/*
* LET'S DO THE SENDING
*/
I made an contact form in codeigniter so users can contact me but when I try to send the email nothing is send. I don't know why it happens. Also I know This has been asked before but I only want to know if there's something wrong with my code.
This is my controller:
<?php
class Contactform extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation', 'email'));
}
function index()
{
//set validation rules
//$this->form_validation->set_rules('name', 'Name', 'trim|required|xss_clean|callback_alpha_space_only');
//$this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email');
//$this->form_validation->set_rules('subject', 'Subject', 'trim|required|xss_clean');
//$this->form_validation->set_rules('message', 'Message', 'trim|required|xss_clean');
//run validation on form input
if ($this->form_validation->run() == FALSE)
{
//validation fails
$this->load->view('contact_form_view');
}
else
{
//get the form data
$name = $this->input->post('name');
$from_email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
//naar welk email je het wilt sturen
$to_email = 'ferran1004#gmail.com';
//send mail
$this->load->library('email', $config);
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send() == TRUE)
{
// email sent
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
redirect('contactform/index');
}
else
{
//error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
redirect('contactform/index');
}
}
}
//Alleen alfabet letters en spaties code
function alpha_space_only($str)
{
if (!preg_match("/^[a-zA-Z ]+$/",$str))
{
$this->form_validation->set_message('alpha_space_only', 'The %s field must contain only alphabets and space');
return FALSE;
}
else
{
return TRUE;
}
}
}
?>
This is my view:
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3 well">
<?php $attributes = array("class" => "form-horizontal", "name" => "Contactform");
echo form_open("Contactform/index", $attributes);?>
<fieldset>
<legend>Contact Form</legend>
<div class="form-group">
<div class="col-md-12">
<label for="name" class="control-label">Name</label>
</div>
<div class="col-md-12">
<input class="form-control" name="name" placeholder="Your Full Name" type="text" value="<?php echo set_value('name'); ?>" />
<span class="text-danger"><?php echo form_error('name'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="email" class="control-label">Email ID</label>
</div>
<div class="col-md-12">
<input class="form-control" name="email" placeholder="Your Email ID" type="text" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="subject" class="control-label">Subject</label>
</div>
<div class="col-md-12">
<input class="form-control" name="subject" placeholder="Your Subject" type="text" value="<?php echo set_value('subject'); ?>" />
<span class="text-danger"><?php echo form_error('subject'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="message" class="control-label">Message</label>
</div>
<div class="col-md-12">
<textarea class="form-control" name="message" rows="4" placeholder="Your Message"><?php echo set_value('message'); ?></textarea>
<span class="text-danger"><?php echo form_error('message'); ?></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input name="submit" type="submit" class="btn btn-primary" value="Send" />
</div>
</div>
</fieldset>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</div>
</div>
</div>
This is my email.php file in my config folder:
<?php
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xxxxx#gmail.com'; //change this
$config['smtp_pass'] = 'xxxxxxx'; //change this
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
?>
When I click on send, no email is send.
you can configure Google SMTP server as follows
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'youremail#gmail.com';
$config['smtp_pass'] = 'youremailpassword';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // html or text
$config['validation'] = TRUE; // bool whether to validate email or not
Google's SMTP server requires authentication, so here's how to set it up:
SMTP server (i.e., outgoing mail): smtp.gmail.com
SMTP username: Your full Gmail or Google Apps email address (e.g example#gmail.com or example#yourdomain.com)
SMTP password: Your Gmail or Google Apps email password
SMTP port: 465
SMTP TLS/SSL required: yes
In order to store a copy of outgoing emails in your Gmail or Google Apps Sent folder, log into your Gmail or Google Apps email Settings and:
Click on the Forwarding/IMAP tab and scroll down to the IMAP Access section: IMAP must be enabled in order for emails to be properly copied to your sent folder.
for more https://www.digitalocean.com/community/tutorials/how-to-use-google-s-smtp-server
OR Codeigniter email sending is not working
since this seems to be a matter of urgency because there are a ton of questions lately regarding codeigniter & sending mails, i try to explain what you could do to find out your problem
1. installing PHP Mailer
CI doesn't provide that much information, in order to find out what's wrong with your attempt to send emails - i suggest to use PHP Mailer for that purpose.
Download the latest PHPMailer Build from Github.
You can find the project here
Click now on "clone or download" and download it as zip - as in the image below is shown.
Create a Folder phpmailer where Codeigniters index.php lies.
The root folder in this zip File is called - PHPMailer-master.
Unzip it to your phpmailer directory and rename the folder to lib.
You should see something like
2. Using PHP Mailer
first of all i'm not writing down here what stays in the Documentation or can found elsewhere
The following links are useful for you to study PHPMailer
Troubleshooting
API
Examples
Create a php file called mail.php within your phpmailer directory.
An example could be:
require_once("./lib/PHPMailerAutoload.php");
echo "<pre>";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = '0.0.0.0';
$mail->SMTPAuth = true;
$mail->Username = "yyy";
$mail->Password = "xxx";
$mail->Port = 25;
$mail->SMTPDebug = 2;
$mail->From = 'office#example.com';
$mail->FromName = 'John Doe';
$mail->addAddress('john.doe#example.com', 'John Doe');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
if(!$mail->send()) {
echo '<br />Message could not be sent.';
echo '<br />Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
3. Finishing investigating your problem
the most important thing here is, you've to separate your mail problem from Codeigniter. If you manage to send emails via PHP Mailer, it should be easy to integrate it with CI.
As long as you are not able to send these mails, you should debug it
with PHPMailer.
if you call now your mail.php file via browser you should be able to see enough information in order to investigate your problem.
One last word:
look #your spam folder too ;)
change this code in your config email.php:
$config['protocol'] = 'smtp';
to this:
$config['protocol'] = 'mail';
source here
I have a website form where someone can send me a message. They have to enter their name, email and a message.
The form works to a point in that I get the email and the senders name and email they entered is shown in the email, but not the message they enter.
Can anyone see where the problem lies please?
Here is the HTML form
<form method="post" action="php/mail.php" name="cform" id="cform">
<input name="name" id="name" type="text" class="col-xs-12 col-sm-6 col-md-6 col-lg-6" placeholder="Your name..." >
<input name="email" id="email" type="email" class=" col-xs-12 col-sm-6 col-md-6 col-lg-6 noMarr" placeholder="Your email..." >
<textarea name="message" id="message" cols="" rows="" class="col-xs-12 col-sm-12 col-md-12 col-lg-12" placeholder="Your message..."></textarea>
<input type="submit" id="submit" name="send" class="submitBnt" value="Send message">
</form>
And here is the php/mail.com that is uses (connection details changed to anonymous details)
<?
require("class.phpmailer.php");
//form validation vars
$formok = true;
$errors = array();
//sumbission data
$ipaddress = $_SERVER['REMOTE_ADDR'];
$date = date('d/m/Y');
$time = date('H:i:s');
//form data
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP - mail or smtp.domain.com
$mail->Host = "myhost.myprovider.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "info#myaddress.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
$mail->From = "info#myaddress.com"; // SMTP username
$mail->AddAddress("info#myaddress.com"); // Your Adress
$mail->Subject = "New contact request from ME !";
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Body = "<p>You have recieved a new message from the enquiries form on your website.</p>
<p><strong>Name: </strong> {$name} </p>
<p><strong>Email Address: </strong> {$email} </p>
<p><strong>Subject: </strong> {$subject} </p>
<p><strong>Message: </strong> {$message} </p>
<p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
if(!$mail->Send())
{
echo "Mail Not Sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
There is no reason for, as you say, name and email to be shown and message to be not.
I think you need enctype for textareas ... but im not completely sure. Try it, it wont hurt you:
<form enctype="multipart/form-data" method="post" action="php/mail.php" name="cform" id="cform">
Might want to take a look at this similar question
Someone had the same issue and all the had to do was change the id and name to something different
Issue using $_POST with a textarea
As to the issue with the subject being shown I saw you commented about, you never pass a subject to $_POST unless you are in some other code that is not posted
EDIT 1:
If you are manually setting the subject then why try to get it from $_POST as well as trying to do <p><strong>Subject: </strong> {$subject} </p> will not work because $subject has no value from $_POST