PHPMailer send mail with array ( $_POST['email'] ) - php

Hi I have question about HTML and PHP array form. In the HTML form I ask 3 emails and send them to my database.
Someone knows how to make it work please? Thanks!
HTML FORM:
<form id="formulario" method="post" action="php/enviar.php" enctype="multipart/form-data">
<input type="email" name="email" required>
<input type="email" name="email1" required>
<input id="submit" type="submit" name="enviar" value="Send mail">
</form>
PHPMailer Part:
$para1 = $_POST['email'];
$para2 = $_POST['email1'];
$recipientes = array('joglym#gmail.com', 'jorgeloaiza12#gmail.com');
foreach($recipientes as $email)
{
$mail->AddAddress($email);
print_r($email); //only test
}
Error:
Invalid address: emailemail
Invalid address: email1email1
You must provide at least one recipient email address.
Thanks, sorry for my bad english!

First of all,I do not think you have implemented the PHPMailer the rght way.
Take a look at the PHPMailer github link for the simple example on how it is implemented.
1) You have to first include the PHPMailer class in your code
2) Then initialize the PHPMailer like $mail = new PHPMailer;. Have to set all the properties of the initialized object and then send mail.
You have mentioned about sending the datas to database although you have not provided any code of what you are trying to do

Related

How to fix this php file for sending email

i have created this php form for enquiry purpose but when i clicked on the submit button it's not working. can you tell me what have i done wrong in this code.
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type ="text" name="subject" placeholder="subject">
<input type ="email" name="email" placeholder="email">
<textarea rows="5" name="message" cols="30"></textarea>
<input class="btn" type="submit" name="submit" value="Submit">
</form>
<?php
if(isset($_POST['submit'])){
$to = "rizwandesigns19#gmail.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_POST['email'];
$headers = "From : $from";
mail($to, $subject, $message, $headers);
}
echo "Mail Sent";
?>
or can you give me valid php script for this purpose.
To get through google's and other's spam filters you need an address which the mail is sent from. For this you could create a new Gmail-address and use the phpmailer-library.
Edit: Setup with gmail is actually pretty complicated and it will disable your access once in a while which renders it almost unuseable. I started to do it by installing a real mail server on the host machine (Install a Complete Mail Server with Postfix and Webmail in Debian 9) and use the php mail() function (phpmailer can still be used tho).

How do i automatically send an email after user submit their email address in the newsletter form?

I want to automatically send an email that says "thank you for signing up for our newsletter form. If you have any questions please email kundeservice#.....no
I have tried multiple different codes that I tried to change but nothing has worked. I need to use the $_GET['epost'] so I send it correctly to the email.
I am not sure if I need to install something on the terminal. Currently using ubuntu 18.04
HTML:
<form name="form" class="forms" action="/backup/formsend.php" id="formn" method="post" >
<div class="email">
<input type="text" name="epost" id="epost" placeholder="E-Post" required>
</div>
<div class="submitknapp">
<input class="knapp" type="submit" name="submit" value="Send"></input>
</div>
</form>
<?php
$email = $_POST['epost'];
$email_subject = "News letter";
$email_content = "thank you for signing up for our newsletter form. If you have any questions please email kundeservice#.....no";
mail($email,$email_subject,$email_content);
?>
mail() function is used to send email to mentioned email address.

Can't get form to work

I've searched through the forums and found a lot of threads on this topic but can't seem to find the correct answer or solution for my problem.
I've got a contact form which I can't seem to get working.
HTML:
<form action="php/index.php" id="contact-form" method="post" name="form">
<div>
<label>
<span>Naam: (verplicht)</span>
<input name="vname" placeholder="Uw naam" type="text" tabindex="1" required>
</label>
</div>
<div>
<label>
<span>Email: (verplicht)</span>
<input name="vemail" placeholder="Uw e-mail adres" type="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Telefoon:</span>
<input name="vphone" placeholder="Telefoon nummer" type="tel" tabindex="3">
</label>
</div>
<div>
<label>
<span>Bericht: (verplicht)</span>
<textarea name="msg" placeholder="Uw vraag of opmerking" tabindex="4" required></textarea>
</label>
</div>
<div>
<input id="send" name="submit" type="submit" value="VERZENDEN">
</div>
</form>
<!-- /Form -->
And here is the PHP code, I replaced my e-mail adress in the form with MY EMAIL for obvious reasons.
<?php
if(isset($_POST['submit'])) {
$name = $_POST['vname'];
$remark = $_POST['msg'];
$from_add = $_POST['vemail'];
$to_add = "MY EMAIL";
$subject = "Your Subject Name";
$phone = $_POST['vphone'];
$headers = 'From: $from_add';
if ($phone != null){
$message = "Naam:$name \n Opmerking: $remark \n mijn telefoon nummer is $phone";
mail($to_add,$subject,$message,$headers);
}else{
$message = "Naam:$name \n Opmerking: $remark";
mail($to_add,$subject,$message,$headers);
}
}
?>
Ow I am using XAMPP to run a localhost, perhaps that could be the problem but I'm not sure.
using the php mail driver aint good for several reasons ,
u can instead try something call phpmailer http://phpmailer.worxware.com which will teach u a better way of doing things like that without frustration ,also incase later u wanted to use a php framework u will feel right at home because they will mostly be using the same syntax.
note that sending mails at first may take some time ,maybe even hours b4 u get anything ,for that u can use something like a fakesmtp https://nilhcem.github.io/FakeSMTP/ to catch the emails.
I had that same problem with a horrible server which doesn't send emails.
So I used a code that connects to a gmail account and sends the email from there.
try this tutorial:
http://coded-words.tumblr.com/post/6936532107/configure-gmail-as-smtp-in-xampp-to-send-mail
Edit 23.12.2014:
Do you have something like this in your code?
<?php
$message = "The mail message was sent with the following mail";
$headers = "From: youremail#gmail.com";
mail("youremail#gmail.com", "Testing", $message, $headers);
?>
(source: http://jiansenlu.blogspot.co.il/2014/10/php-mail-function-using-gmail-account.html)
If you do have this code:
Try submitting a different email address than the one you used in your code.
Sometimes it goes to the "Sent mail" in your Gmail account without actually showing you that you received a new email. (So you can check your "Sent mail" to see if there is anything over there).

My HTML contact form to PHP mail isn't working [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have a decent understanding of HTML and CSS but completely novice when it comes to PHP. I've scouted the net and tried this out with multiple different tutorials, however I can't seem to tailor the php code to work with my contact page's email form. (www.richseeley.com/contact)
Ultimately, I would like this form to confirm the message being sent with a pop up window, without leaving the page, but so far I can't even get it to work in the most basic sense.
At present, it is echoing the "thank you for using our mail form", however the email isn't sending.
Here is the html coding for my contact form:
<div id="form-main">
<div id="form-div">
<form class="form" id="form1" action="scripts/test.php" method="post" enctype="text/plain">
<input name="name" type="text" class="feedback-input" placeholder="Name" id="name" />
<input name="email" type="text" class="feedback-input" id="email" placeholder="Email" />
<textarea name="message" class="feedback-input" id="message" placeholder="Message"></textarea>
<input type="submit" value="SEND" id="button-blue"/>
</form>
</div>
</div>
And here is the PHP code that I have most recently been trying to work with:
<?php
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail("r*******#gmail.com", $name,
$message, "From:" . $email);
echo "Thank you for using our mail form";
?>
I appreciate that this is a fairly simple problem I am trying to solve, but I've spent several hours with no success, and I really don't want to have to compromise the design of my work/website, and end up using something less stylised, as a basic tutorial would provide.
The only way I could think of doing it would be something like:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
echo <p>Are you sure you want to do this?</p>
<form action="send_mail.php" method="post">
<input type="submit" name="ok" value="OK" />
<input type="submit" name="cancel" value="Cancel" />
</form>
?>
and in send_mail.php:
<?php>
//send email
if (isset($_POST['ok'])) {
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
mail("richsee******#****.com", $name,
$message, "From:" . $email);
echo "Thank you for using our mail form";
}
}
if (isset($_POST['cancel'])) {
header('Location: didnt_confirm.html");
}
?>
Also, your php seems wrong and vulnerable, but all you're asking is for a confirmation ;)
If you're concerned about vulnerability (header injections), you can read this.

Help With Notify Me Form

I'm trying to make a simple form like this http://birdboxx.com/, where the user can enter their email address to be notified when our site has launched.
I've looked at the HTML their using and it all looks pretty simple, I'm just not sure on how to code the PHP part. Could someone maybe help me out?
Thanks in advance.
The form in the given example (the relevant parts):
<form name="form-email-submit" id="form-email-submit" action="add_email.php" method="POST">
<input type="text" id="input-email" name="input-email" value="Enter your email here"/>
<input type="submit" title="Notify Me" value="Notify Me">
</form>
In your PHP script:
//In the add_email.php
$notificationEmail = $_POST['input-email']; // from the name="input-email" in the form
So now you have the email submitted, you can do whatever you want with it. You can write it to a file, or save it to a database, or whatever.
Basic solution for the email saving part.
The HTML:
<form method="post" action="">
<input type="email" name="email" placeholder="Enter your email here" /> <input type="submit" name="send" value="Notify me" />
</form>
The PHP with MySQL for saving:
$dbhost = "your host";
$dbuser = "your username";
$dbpass = "your password";
$dbname = "database name";
$c = #mysql_pconnect($dbhost,$dbuser,$dbpass) or die();
#mysql_select_db($dbname,$c) or die();
//It isn't secure in this state: validation needed as it is an email?
if(isset($_POST['send'])){
$email = mysql_real_escape_string($_POST['email']);
mysql_query('INSERT INTO email (id,email) VALUES (NULL,'.$email.');');
}
For sending emails I recommend phpmailer or any other solution: http://phpmailer.worxware.com/

Categories