PHPMailer sending mail without form data [duplicate] - php

This question already has answers here:
method="post" enctype="text/plain" are not compatible?
(2 answers)
Closed 8 years ago.
I have a css div html form for a contact page and would like the form to be emailed when sent. Being a newbie at PHP ive tried different examples and can get the mail to be sent but cant get the form data with in the email.
html code
<div class="maincontent">
<div class="content">
<article class="topcontent">
<content>
<div id="form-main">
<div id="form-div">
<form method="post" enctype="text/plain" action="mail.php" class="form" id="form1">
<p class="name">
<input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Name" id="name" />
</p>
<p class="email">
<input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
</p>
<p class="text">
<textarea name="text" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Comment"></textarea>
</p>
<div class="submit">
<input type="submit" value="SEND" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
</div>
</content>
</article>
</div>
</div>
PHP Mail Script
<?php
require("class.phpmailer.php");
$formcontent="From: $name \n Message: $text \n Email: $email";
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "localhost;"; // specify main and backup server
$mail->SMTPAuth = false; // turn on SMTP authentication
$mail->Username = "jswan"; // SMTP username
$mail->Password = "secret"; // SMTP password
$name = $_POST['name']; // contain name of person
$email = $_POST['email']; // Email address of sender
$message = $_POST['text']; // Your message
$mail->AddAddress('warren#.com', 'recipient email');
$mail->From = "noreply#.com";
$mail->FromName = "Contact Us Information";
$mail->Subject = "Website Contact Us Information";
$mail->Body = "Name:{$name}\n\nEmail:{email}\n\nComments:{$body}";
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
Like I said, mail is sent but without the form information.
Thanks

Take out enctype="text/plain" from the form tag.
Using this you can not get the posted data.

Related

Unable to Send Email from HTML Form With PHP(gmail) [duplicate]

This question already has answers here:
Debugging PHP Mail() and/or PHPMailer
(1 answer)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
i'm trying to send that form via gmail :
<!-- form -->
<form name="contactForm" id="contactForm" method="post" action="inc/sendEmail.php">
<fieldset>
<div class="form-field">
<input name="contactName" type="text" id="contactName" placeholder="Nom" value="" minlength="2" required="">
</div>
<div class="form-field">
<input name="contactEmail" type="email" id="contactEmail" placeholder="Email" value="" required="">
</div>
<div class="form-field">
<input name="contactSubject" type="text" id="contactSubject" placeholder="Sujet" value="">
</div>
<div class="form-field">
<textarea name="contactMessage" id="contactMessage" placeholder="message" rows="10" cols="50" required=""></textarea>
</div>
<div class="form-field">
<button class="submitform">Submit</button>
<div id="submit-loader">
<div class="text-loader">Sending...</div>
<div class="s-loader">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
</fieldset>
</form> <!-- Form End -->
I've checked with the developer tools and everything is send correctly
My php file is in the inc folder :
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';
if(isset($_POST["submit"])){
$username = 'myadress#gmail.com';
$password = 'mypass';
$to = $username;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = $username;
$mail->Password = $password;
$mail->SetFrom($_POST["contactName"." "."contactEmail"]);
$mail->Subject = $_POST["contactSubject"];
$mail->Body = $_POST["contactMessage"];
$mail->AddAddress($to);
if(!$mail->Send())
{
echo "Mailer error : " . $mail->ErrorInfo . "<br>";
}}
Actually i can't see any error but i receive no mail so something is wrong
(indentation here isn't correct but it's good in my code)
Actually i googled for some solutions but no one has worked for it, what am i missing ?

Why is my form no longer showing up?

I created a contact form in a PHP project and I have been trying to get the mail to send and in the process I have been altering some code such as removing my contact form. Now I re-added the form, but it does not display on the browser:
This is the actual file called contact.php:
<?php
define("TITLE", "Contact Us | MicroUrb");
include('includes/header.php');
/**
* PHPMailer Autoloader
*/
require '../vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
/**
* Configure PHPMailer with your SMTP server settings
*/
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'myemail#example.com';
$mail->Password = 'secret';
$mail->SMTPSecure = 'tls';
/**
* Enable SMTP debug messages
*/
$mail->SMTPDebug = 2;
/**
* Send an email
*/
$mail->setFrom('sender#gmail.com');
$mail->addAddress('recipient#gmail.com');
$mail->Subject = 'An email sent from PHP';
$mail->Body = 'This is a test message';
if ($mail->send()) {
echo 'Message sent!';
} else {
echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>
<div id="contact">
<hr>
<h1 class="contact">Get in touch with us!</h1>
<form method="post" action="" id="contact-form">
<label for="name">Your name</label>
<input type="text" id="name" name="name">
<label for="email">Your email</label>
<input type="email" id="email" name="email">
<label for="message">and your message</label>
<textarea id="message" name="message"></textarea>
<input type="checkbox" id="subscribe" name="name" value="Subscribe">
<label for="">Subscribe to newsletter</label>
<input type="submit" class="button next" name="contact_submit" value="Send Message">
</form>
<hr>
</div>
<?php include('includes/footer.php'); ?>

Mailer with php not working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
This is code of my form.
<form method="post" action="mailer.php" id="contactfrm">
<div class="col-sm-4">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter name" title="Please enter your name (at least 2 characters)">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" id="email" placeholder="Enter email" title="Please enter a valid email address">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="comments">Message</label>
<textarea name="message" class="form-control" id="comments" cols="3" rows="5" placeholder="Enter your messageā€¦" title="Please enter your message (at least 10 characters)"></textarea>
</div>
<button name="submit" type="submit" class="btn btn-lg btn-primary" id="submit">Submit</button>
<div class="result"></div>
</div>
</form>
Here My mailer.php
<?php
$replyemail="my email";
$name = $_POST["name"];
$email = $_POST["email"];
$thesubject = "Project With Me Query";
$themessage = $_POST["message"];
$success_sent_msg='<p align="center"><strong> </strong></p>
<p align="center"><strong>Your message has been successfully sent to My Email<br>
</strong> and I will reply as soon as possible.</p>
<p align="center">A copy of your query has been sent to you.</p>
<p align="center">Thank you for contacting Me.</p>';
$replymessage = "Hi $name
Thank you for your email.
We will endeavour to reply to you shortly.
Please DO NOT reply to this email.
Below is a copy of the message you submitted:
--------------------------------------------------
Subject: $thesubject
Query:
$themessage
--------------------------------------------------
Thank you";
$themessage = "name: $name \nQuery: $themessage";
mail("$replyemail",
"$thesubject",
"$themessage",
"From: $email\nReply-To: $email");
mail("$email",
"Receipt: $thesubject",
"$replymessage",
"From: $replyemail\nReply-To: $replyemail");
echo $success_sent_msg;
echo '<script>setTimeout(function(){location.href="index.php"} , 5000); </script>';
?>
I am unable to figure out what wrong I've done.
whenever i fill out information in for a Success Message displayed. but i didn't get any email of that information.
can someone fix this existing code or provide me a new mailer code?
Your form
<form method="post" action="1.php" id="contactfrm">
<div class="col-sm-4">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter name" title="Please enter your name (at least 2 characters)">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" id="email" placeholder="Enter email" title="Please enter a valid email address">
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="comments">Message</label>
<textarea name="message" class="form-control" id="comments" cols="3" rows="5" placeholder="Enter your messageā€¦" title="Please enter your message (at least 10 characters)"></textarea>
</div>
<button name="submit" type="submit" class="btn btn-lg btn-primary" id="submit">Submit</button>
<div class="result"></div>
</div>
</form>
Your php code with smtp
<?php
if(isset($_POST["submit"])){
$replyemail="my email";
$name = $_POST["name"];
$email = $_POST["email"];
$thesubject = "Project With Me Query";
$themessage = $_POST["message"];
$success_sent_msg='<p align="center"><strong> </strong></p>
<p align="center"><strong>Your message has been successfully sent to My Email<br>
</strong> and I will reply as soon as possible.</p>
<p align="center">A copy of your query has been sent to you.</p>
<p align="center">Thank you for contacting Me.</p>';
$replymessage = "Hi $name
Thank you for your email.
We will endeavour to reply to you shortly.
Please DO NOT reply to this email.
Below is a copy of the message you submitted:
--------------------------------------------------
Subject: $thesubject
Query:
$themessage
--------------------------------------------------
Thank you";
$themessage = "name: $name \nQuery: $themessage";
include "PHPMailer_5.2.4/class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "yourusername#gmail.com";
$mail->Password = "yourgmailpassword";
$mail->AddReplyTo($replymessage, "Reply name");
$mail->AddAddress($email,'ashu');
$mail->Subject = "SMTP Receivced";
$mail->Body = "<b>Succesfully SMTP Receivced</b>";
$mail->MsgHTML($success_sent_msg);
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = 'index.php';
$crlf = "\n";
$hdrs = array(
'From' => 'you#yourdomain.com',
'Subject' => 'Test mime message'
);
if($mail->send($hdrs))
{
echo "<script> alert('Successfully Mailed');window.location = '';</script>";
}
else{
echo "Mailed Error: " . $mail->ErrorInfo;
}
}
//echo '<script>setTimeout(function(){location.href="pra-2.php"} , 5000); </script>';
?>

Can't set the sender name, his email and subject in phpmailer

My phpmailer sends messages without sender name, sender email and subject of message.
I need receive message like this:
Name: sender name
Email: sender#gmail.com
Subject: Business
Message: text of message .................... ............. ............
Please help me to fix it to receive sender name, email and subject. Thank you.
Here is my php file:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="EN" />
<title> Contact Form</title>
</head>
<body>
<?php
//receive and save all informations
$name=$_POST['Name'];
$from=$_POST['E-mail'];
$subject=$_POST['Subject'];
$message=$_POST['Message'];
// reading PHPmailer
require("phpmailer/class.phpmailer.php");
include("phpmailer/class.smtp.php");
$mail = new phpmailer(true);
$mail->IsSMTP();
try {
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'eric21#gmail.com';
$mail->Password = 'ter3221';
$mail->SMTPAuth = true;
$mail->SetFrom("$from",'website');
$mail->AddAddress('eric#gmail.com','message has been sent. contact us');
$mail->Subject='Website message';
$mail->CharSet='UTF-8';
$mail->ContentType='text/html';
$mail->MsgHTML("$message");
if (!$mail->send()) {
echo 'your message was not sent. Tap "Try Again" to send the message.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo '<div class="alert alert-success container text-center" style="text-align:center" role="alert">
<big><b><br><br><br>Message has been sent!<br></big></b>
</div>
<div class="alert alert-success container text-center" style="text-align:center" role="alert">
<big><b><button>Back </big></b></button>
</div>';
}
} catch(phpmailerException $e) {
echo "<p class='message alert alert-danger'>" . $e->errorMessage() . "</p>";
} catch(Exception $e) {
echo "<p class='message alert alert-danger'>" . $e->getMessage() . "</p>";
}
?>
</body>
</html>
here is my form
<form class="form" id="form-main" method="Post" action="1.php">
<p class="name">
<input name="Name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Name" id="name" />
</p>
<p class="e-mail">
<input name="E-mail" type="text" class="validate[required,custom[email]] feedback-input" id="e-mail" placeholder="E-mail" />
</p>
<p class="subject">
<input name="subject" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="subject" id="subject" />
</p>
<p class="text">
<textarea name="message" class="validate[required,length[6,300]] feedback-input" id="message" placeholder="Message"></textarea>
</p>
<div class="submit">
<input type="submit" value="SEND" id="button-blue"/>
<div class="ease"></div>
</div>
</form>
You've based your code on an obsolete example and are probably using an old version - get the latest. If you want those submitted fields to appear in the message, you need to append them to $message, or to $mail->Body after calling msgHTML(). This will make you a plain-text body with that content in:
$mail->isHTML(false);
$mail->Body = "Name: $name
Email: $email
Subject: $subject
Message: $message";

send mail with attachment using phpmailer and html form

i am trying to send mail from one to other using gmail smtp.
the mail sent successfully but without attachment. how can i solve this?
html form:
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendresume.PHP" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-5">
<div class="form-group">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
</div>
<div class="form-group">
<input type="text" name="mobile" class="form-control" required="required" placeholder="Mobile number">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" required="required" placeholder="Email address">
</div>
<p class="lead" style="margin-bottom: 10px;">Resume :</p>
<div class="form-group">
<input type="file" name="file" class="form-control" required="required" >
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg">Send Message</button>
</div>
</div>
<div class="col-sm-7">
<textarea name="messege" id="message" class="form-control" rows="8" placeholder="Note"></textarea>
</div>
</div>
</form>
and php code is:
<?php
include "classes/class.phpmailer.php"; // include the class name
$email = $_POST["email"];
$messege=$_POST['messege'];
$name=$_POST['name'];
$mobile=$_POST['mobile'];
$mail = new PHPMailer(); // create a new object
$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; // or 587
$mail->IsHTML(true);
$mail->Username = "abc#gmail.com";
$mail->Password = "mypassword";
$mail->SetFrom("feedback#abc.com");
$mail->Subject = "this is subject";
$mail->Body = "this is body <br/><br/><br/><br/>
name:$name <br/><br/>
email:$email<br/><br/>
mobile:$mobile<br/><br/>
messege:$messege</b>";
$mail -> Addattachment('here is problem');
$mail->AddAddress("mymail#gmail.com");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "mail sent";
}
?>
this mail is sent successfully but I want it with attachment. file store in directory is not important. hope this problem solve immediately. thanks in advance because I never learned an used php before.
Here is an example to send attachment using PHPMailer class:
http://tournasdimitrios1.wordpress.com/2011/11/08/a-simple-example-sending-email-with-attachment-using-phpmailer/

Categories