Why is my form no longer showing up? - php

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'); ?>

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 ?

PHPMailer Laravel attachment from form not working

i'm trying to add a PDF attachment in my PHPmailer but it won't send the attachment.
Controller:
$recipient = Request::input('emailaddress');
$recipientName = Request::input('name');
$file = Request::input('file');
$mail = new \PHPMailer(true);
try {
$mail->isSMTP();
$mail->CharSet = "utf-8";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.sendgrid.net";
$mail->Port = 587;
$mail->Username = "username";
$mail->Password = "password";
$mail->setFrom("info#email.nl", "Business");
$mail->Subject = "Offerte";
$mail->MsgHTML("Test.");
$mail->addAddress($recipient, $recipientName);
if (isset($_FILES[$file]) &&
$_FILES[$file]['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES[$file]['tmp_name'],
$_FILES[$file]['name']);
}
$mail->send();
} catch (phpmailerException $e) {
dd($e);
} catch (Exception $e) {
dd($e);
}
return back()->with('send', 'send');
}
The form:
<form method="POST" action="/offer/sendmail">
<div class="form-group">
<label for="name">Aan:</label>
<input type="text" class="form-control" id="name" name="name" value="{{$offers->name}}">
</div>
<div class="form-group">
<label for="emailaddress">Email-adres:</label>
<input type="text" class="form-control" id="emailaddress" name="emailaddress" value="{{$offers->email}}">
</div>
<div class="form-group">
<label for="subject">Onderwerp:</label>
<input type="text" class="form-control" id="subject">
</div>
<div class="form-group">
<label for="subject">Bericht:</label>
<textarea class="form-control" rows="5" id="comment"></textarea>
</div>
<div class="form-group">
<label for="subject">Voeg een bestand toe:</label>
<input type ="file" name='file' id='uploaded_file'>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Verzenden</button>
</form>
It does send the email but there is no attachment in it. Do you have any idea why? I've also changed $mail->username and password so i can keep my credentials private.
This code is unsafe; you're trusting values from $_FILES. You need to call is_uploaded_file or move_uploaded_file. Read the PHP docs on handling uploads.
On a more basic level, you have not set the enctype attribute on the form, so file elements will not work - you need to add enctype="multipart/form-data", so your form tag will become.
<form method="POST" action="/offer/sendmail" enctype="multipart/form-data">
It's a good idea to set a MAX_FILE_SIZE element too.
Base your code on the send_file_upload example provided with PHPMailer, which handles uploads correctly and safely.

PHP email working correctly but not actually being received by the user

Once the form is submitted with correct information a message will appear informing the user that the email was sent. however for some reason the email is not being received by the user.
I have already checked online but to no avail. Can someone kindly help me solve this issue?
The following is the code for both the HTML form and PHP.
<form method="POST" action="contact.php">
<div class="row">
<div class="col-sm-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Name" type="text" required>
</div>
<div class="col-sm-6 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required>
</div>
</div>
<textarea class="form-control inputStyle" id="comments" name="comments" placeholder="Comment" rows="6" required></textarea>
<br>
<div class="row">
<div class="col-sm-12 form-group">
<button class="btn btn-default pull-right" name="submit" type="submit">Send</button>
</div>
</div>
<!-- Contacting Support Team -->
<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
$name = $_POST['name'];
$comment = $_POST['comments'];
if(!empty($email) && !empty($name) && !empty($comment)){
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->Host = 'ssl://smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->Port = 465;
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '*****'; // SMTP username
$mail->Password = '*****'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = '*****';;
$mail->addAddress($email); // Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Test';
$mail->Body = '$comment';
$mail->AltBody = '$comment';
if(!$mail->send()) {
echo '<div class="alert alert-danger alert-dismissible" id="myAlert">
×
<strong> Email not sent </strong> Something went wrong.
</div>';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo '<div class="alert alert-success alert-dismissible" id="myAlert">
×
<strong> Email sent!</strong> We will contact you as soon as possible.
</div>';
}
}
}
?>
</form>
Thanks in advance!
You're setting
$mail->SMTPSecure = 'tls';
but port 465 is the Gmail SSL port. 587 is the TLS port. So either switch the port, or change to using
$mail->SMTPSecure = 'ssl';

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/

PHPMailer sending mail without form data [duplicate]

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.

Categories