Can any one help me to integrate a form with PHPMailer. I have following form.
<form method="POST">
<p>Name:<input type="text" name="name" size="30"></p>
<p>Email Address:<input type="text" name="email" size="30"></p>
<input type="submit" name="submit" value="Submit">
</form>
I just need to display POST variables in my receiving email's body. I have search and refer alot and spend hours in it, everyone clarifies it with high level explanation. As i am not a programmer can anyone explain me how can i do this with simple explanation. I just done a method as follows but it did'nt work.
$name = $_POST['name'];
$email = $_POST['email'];
$mail->Body = "
<html>
<h2><b>".$name." ".$email."</b></h2>
</html>";
When i tried the above method i am getting error in this line '$name = $_POST['name'];'. The error message is: Notice: Undefined index:' I think i am wrong with my placing order of codes.
Thanks in advance!
<?php
if(array_key_exists("name",$_POST) && $_POST["name"] != "" && array_key_exists("email",$_POST) && $_POST["email"] != ""){
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // 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 = 'mail#gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('mail#gmail.com', 'Manager');
$mail->addAddress('mail#gmail.com', 'Administrator'); // Add a recipient
$name = $_POST['name'];
$email = $_POST['email'];
$mail->Body = "<h2><b>".$name." ".$email."</b></h2>";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
} else {
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="POST">
<p>Name:<input type="text" name="name" size="30" required></p>
<p>Email Address:<input type="email" name="email" size="30" required></p>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
}
?>
Related
There is a really old blog entry from Twilio about testing the TTS in browser:
https://www.twilio.com/blog/2011/08/testing-twilios-text-to-speech-engine-using-twilio-client.html
Unfortunately it doesn't contain enough information to put a test together. It also contains a number of dead links and mentions a Github project that I can't find.
I'd really like for users to have the ability to hear what their announcement will sound like prior to firing off the form and starting the phone calls.
I use Lasso (which fires off CURL requests to the Twilio REST API), but any kind of tutorials or hints would be appreciated.
If you set up a demo account on Twilio and use Glitch online php tester (https://glitch.com/edit/#!/php-poc) or a local environment you can create a workable example like I did. You will need to fill in the empty strings to correspond to your app name. Search for TwiML in the website to get to the right section to set the right url of your server that TWilio will call upon request to read content (xml). In my case url was http://<server>/?incoming-call.php tested on Glitch.
You need to grab the Twilio PHP SDK and include the Services/Twilio/Capability.php from https://github.com/twilio/starter-php in your server code.
<?php
require __DIR__ . '/../vendor/autoload.php';
$url = [];
$url = explode('?', $_SERVER['REQUEST_URI']);
if (count($url) == 2 && $url[1] == 'incoming-call.php')
{
header('Content-type: text/xml');
$response = new Twilio\Twiml;
$dialogue = trim($_REQUEST['dialogue']);
$voice = (int) $_REQUEST['voice'];
if (strlen($dialogue) == 0)
{
$dialogue = 'Please enter some text to be spoken.';
}
if ($voice == 1)
{
$gender = 'man';
}
else
{
$gender = 'woman';
}
$response->say($dialogue);
echo $response;
exit;
}
require_once('Services/Twilio/Capability.php');
$accountsid = ''; // YOUR TWILIO ACCOUNT SID
$authtoken = ''; // YOUR TWILIO AUTH TOKEN
$fromNumber = ''; // PHONE NUMBER CALLS WILL COME FROM
$APP_SID = '';
$token = new Services_Twilio_Capability($accountsid, $authtoken);
$token->allowClientOutgoing($APP_SID);
?>
<html>
<head>
<title>Text-To-Speech</title>
<script type="text/javascript" src=
"https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript"
src="//media.twiliocdn.com/sdk/js/client/v1.5/twilio.js"></script>
<script type="text/javascript">
Twilio.Device.setup("<?php echo $token->generateToken();?>",{"debug":true});
$(document).ready(function() {
$("#submit").click(function() {
speak();
});
});
function speak() {
var dialogue = $("#dialogue").val();
var voice =
$('input:radio[name=voice]:checked').val();
Twilio.Device.connect({ 'dialogue' :
dialogue, 'voice' : voice });
}
</script>
</head>
<body>
<p>
<label for="dialogue">Text to be spoken</label>
<input type="text" id="dialogue" name="dialogue"
size="50">
</p>
<p>
<label for="voice-male">Male Voice</label>
<input type="radio" id="voice-male" name="voice"
value="1" checked="checked">
<label for="voice-female">Female Voice</label>
<input type="radio" id="voice-female" name="voice"
value="2">
</p>
<p>
<input type="button" id="submit" name="submit"
value="Speak to me">
</p>
</body>
</html>
Sir
this a part of our mini project and the code use to work well without the option to upload an image.Here we are having a folder "missingCaseImage" inorder to stre the uploaded image. But this code shows that the image already exist while pressing procced button
<!DOCTYPE html PUBLIC >
<?php
include("connection.php");
session_start();
if(isset($_POST['proceed']))
{
$ctype=$_POST['id13'];
$email=$_POST['email'];
if($ctype=='Missing'){
$MCImage=$_FILES['missingImage']["name"];
if (file_exists("../missingCaseImage/" . $MCImage))
{
?>
<script>
alert('Image Name already exists');
window.location.href='dem.php';
</script>
<?php
exit;
}
else
{
move_uploaded_file($_FILES["missingImage"]["tmp_name"],"../missingCaseImage/" .
$_FILES["missingImage"]["name"]);
}
}
$insert="insert into cregister(e_mail,image,cs_type,) values('$email','$MCImage')";
mysql_query($insert);
$lastid = mysql_insert_id();
$_SESSION['cno']=$lastid;
header("location:printform.php");
}
?>
<html >
<?php
if(isset($_GET['error'])){$error=$_GET['error'];} else{$error="";} // if error happaning echo this $error msg
?>
<fieldset>
<form id="form1" name="form1" method="post" action="">
<h3>CASE REGISTRATION FORM</h3>
<P>
<label for="id1">EMAIL ID</label>
<input name="email" type="email" class="validate[required,custom[email]]" id="email" value="<?php echo $_SESSION['email'];?>"
readonly/>
<br />
<P>
<label for="id1">CASE TYPE</label>
<select name="id13" class="validate[required]" id="id13" onChange="missingCase(this.value)">
<option>Murder</option>
<option>Robbery</option>
<option>Vehicle</option>
<option>Missing</option>
<option>Others</option>
</select>
<br />
<P style="display:none;" id="missingImageP" >
<label for="missingImage">UPLOAD IMAGE</label>
<input type="file" name="missingImage" class="uploadMC"/>
<p>
<input name="proceed" type="submit" id="proceed" value="PROCEED"? />
<p>
</form>
</fieldset>
</html>
<script>
function missingCase(mc){
//alert(mc);
if(mc=='Missing'){
$('#missingImageP').show();
}
else{
$('#missingImageP').hide();
}
}
</script>
So now the problem is whenever i try to upload a photo and click on proceed button it always displays Image Name already exists... Why is that so how can i rectify it
NOte: All the required script for validation were been included ..
Thankyou in advance...
does anybody know how i get phpmailer to work on an uploaded website.
include("class.phpmailer.php");
include("class.smtp.php");
$mail = new PHPMailer();
$body = "You have been added to the University of Portsmouth project
database. Your password is
'".$_POST['Password']."'
And your username is
'".$_POST['Username']."'
please click the link below, login to the website, select account settings and change
the password to become verified";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tsl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 25; // set the SMTP port
$mail->Username = "projectnateabiola#gmail.com"; // GMAIL username
$mail->Password = ""; // GMAIL password
$mail->From = "projectnateabiola#gmail.com";
$mail->FromName = "Nathan Abiola";
$mail->Subject = "You have been added to the project database, this email is important";
$mail->AltBody = "Please click"; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddReplyTo("projectnateabiola#gmail.com","Webmaster");
$mail->AddAddress($_POST['Email'],"First Last");
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
}
}
The code works when offline, but once i upload it i get the following error when i submit it. Am i missing something like you cant use phpmailer online. Does any body have any potential alternatives. Thanks for any possible help.
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
I use this for my sites. It is a form on a webpage that calls a php file to send an email. I have found that it has issues sometimes on College servers so keep that in mind.
create a file called mailto.php and paste this in (note that you need to put the correct email address in)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Submitted!</title>
</head>
<body>
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "PUT YOUR EMAIL ADDRESS HERE", "Subject: $subject",
$message, "From: $email" );
echo "Your message has been sent successfully!";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>
Then put this in the body of your html file
<form name="formcheck" onsubmit="return formCheck(this);" action="mailto.php" method="post">
<br />
E-mail: <input type="text" name="email" id="email" size="42" />
<br />
<br />
<br/>
Subject: <input type="text" name="subject" id="subject" size="42" />
<br />
<br />
<br />
Message:
<br />
<textarea rows="5" cols="40" name="message" id="message"></textarea>
<br />
<br />
<input type="submit" onClick="return checkmail(this.form.email)" value="Submit" /><input type="reset" />
</form>
Hope this helps and if anyone has suggestions on how to make this better let me know :)
I want to insert data into my fusion table which is public . I looked out at https://developers.google.com/fusiontables/docs/sample_code for help specifically http://code.google.com/p/fusion-tables-client-php/source/browse/trunk/samples/form_example.php . I downloaded the necessary files for this script to run i.e. downloaded clienlogin.php , file.php , sql.php and constants.php. The script is running but rows are not getting inserted and I am not able to find the reason . I have pasted my code ( its a small code .. please have a look at it and let me know the error I am commiting). Essentially I want to insert data into my fusion table after collecting user info through user forms . I don't want to use google forms. Any kind of help / pointers in this direction would be helpful.
<html>
<?php
include('D:\xampp\htdocs\itpold\clientlogin.php');
include('D:\xampp\htdocs\itpold\sql.php');
include('D:\xampp\htdocs\itpold\file.php');
// Table id
$tableid = 3544282;
//Enter your username and password
$username = "ABCD#gmail.com";
$password = "XYZ";
$token = ClientLogin::getAuthToken($username, $password);
$ftclient = new FTClientLogin($token);
// If the request is a post, insert the data into the table
if($_SERVER['REQUEST_METHOD'] == 'POST') {
// Insert form data into table
$insertresults = $ftclient->query(SQLBuilder::insert($tableid,
array('Name'=> $_POST['Name'],
'Location' => $_POST['Location'])));
$insertresults = explode("\n", $insertresults);
$rowid1 = $insertresults[1];
echo $rowid1 ;
}
?>
<head>
<title>Simple Form Example</title>
<style>
body { font-family: Arial, sans-serif; }
</style>
<script type="text/javascript">
// Simple form checking.
function check_form() {
if(document.getElementById('Name').value == '' ||
document.getElementById('Location').value == '') {
alert('Name and location required.');
return false;
}
return true;
}
</script>
</head>
<body >
<h1>Simple Form Example</h1>
<h2>Insert data</h2>
<form method="post" action="forms.php" onsubmit="return check_form();">
Name: <input type="text" name="Name" id="Name" /><br />
Result: <input type="text" name="Location" id="Location" /><br />
<input type="submit" value="Submit" />
</form>
<h2>Table data</h2>
<p>
<?php
// Show the data from table
$table_data = $ftclient->query(SQLBuilder::select($tableid));
$table_data = explode("\n", $table_data);
for($i = 0; $i < count($table_data); $i++) {
echo $table_data[$i] . '<br />';
}
?>
</p>
</body>
</html>
Often, the server is not able to send requests to secure URLs. See the following StackOverflow post for some ideas on how to fix the problem:
Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?
I suspect that this is a permissions problem with your table. Have you made sure that the account your are logging in with is set up as an editor for this table? The easiest way to check this is to go into Fusion Tables as the owner for the table, and click the share link in the upper right hand corner.
I am trying to make it so that this comment form on my wordpress website can not be submitted if the user does not enter enough data into the textarea.
I wrote this for the header
<script>
function CheckLength()
{
var msg_area = document.getElementById("Message");
msg_area.innerHTML = "";
if (document.getElementById("commentarea").value.length < 100) {
msg_area.innerHTML = "YOU DID NOT ENTER ENOUGH INFO FOR YOUR REVIEW";
}
else document.getElementById("commentform").submit();
}
</script>
And my form looks like this
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" name="commentform" id="commentform">
<p><input size="36" type="text" name="author" /> Name <span class="required">*</span></p>
<p><input size="36" type="text" name="email" /> Email <span class="required">*</span> (Not Published)</p>
<p><input size="36" type="text" name="url" /> Website</p>
<p><input size="36" type="text" name="server_ip" id="server_ip" /> Server IP/Hostname</p>
<p><?php show_subscription_checkbox(); ?></p>
<p><textarea name="comment" id="commentarea" cols="100%" rows="20"></textarea></p>
<p align="right"><input type="button" name="submit" id="submit" value="Submit Review" tabindex="5" onClick="CheckLength()"></p>
<span id="Message" style="color:#ff0000"></span>
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
<?php /* do_action('comment_form', $post->ID); */ ?>
</form>
The form spits out the error "YOU DID NOT ENTER ENOUGH INFO FOR YOUR REVIEW" if I type in less then 100 chars, but if I type more then a 100 chars the form does not submit. If I change the input type to submit it does submit, but it doesn't matter if < 100
Change the name of your input button.
The error I get using your markup is that submit is not a function, because it thinks I'm referring to the submit button. The following should work:
<input type="button" name="submitbtn" id="submitbtn" value="Submit Review" tabindex="5" onClick="CheckLength()">
Could you do this?
Put the check in the "onsubmit" event for the form:
<form action="wp-comments-post.php" onsubmit="return CheckLength();" method="post" name="commentform" id="commentform">
You'll have to update you function to return a Boolean:
<script type="text/javascript">
function CheckLength()
{
var msg_area = document.getElementById("Message");
msg_area.innerHTML = "";
if (document.getElementById("commentarea").value.length < 100) {
msg_area.innerHTML = "YOU DID NOT ENTER ENOUGH INFO FOR YOUR REVIEW";
return false;
}
return true;
}
</script>
Then remove the onclick event from your submit button.
Can you try this?
<script>
function CheckLength()
{
var msg_area = document.getElementById("Message");
msg_area.innerHTML = "";
if (document.getElementById("commentarea").value.length < 100)
{
msg_area.innerHTML = "YOU DID NOT ENTER ENOUGH INFO FOR YOUR REVIEW";
return false;
}
else
{
document.getElementById("commentform").submit();
return true;
}
}
</script>