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 :)
Related
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
}
?>
I want to disable the remember me password prompt of IE/firefox/chrome browser
may developer and blog suggest me to add autocomplete ="off" in <form> tag
but it's not working.
Please give suitable answer thank in advance..
//You can change the type of the password field to text before submitting the form
<script type="text/javascript">
function validate() {
return true;
}
function copyPass() {
document.getElementById("hidPassword").value = document.getElementById("passwordField").value;
if (document.getElementById("passwordField").value != "") {
var passwordLength = document.getElementById("passwordField").value.length;
document.getElementById("passwordField").value = "•".repeat(passwordLength);
}
document.getElementById("passwordField").type = 'text';
}
function changeType() {
document.getElementById("passwordField").type = 'password';
document.getElementById("passwordField").value = document.getElementById("hidPassword").value;
}
</script>
<form method="post" action="yoururl" runat="server">
<input type="text" name="username" />
<input type="password" id="passwordField" name="passwordField" onfocus="javascript:changeType()" onblur="javascript: copyPass()" />
<input type="hidden" name="hidPassword" id="hidPassword" value="" />
<input type="submit" runat="server" name="btnsubmit" value="Submit" onclick="javascript:return validate()" />
</form>
Instead of setting autocomplete="off" on a <form> tag, set it on the individual <input> tags.
For browser support, see caniuse.
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...
So here is what I am trying to do,
Lets say there is my url
http://myurl.com/watch?v=**XYZ**&caption=**ABC**&link=**http://google.com**
I want the text in bold as input from user e.g.:
**v**= textfield1
**caption**= textfield2
**link**= textfield3
SUBMIT button
After clicking submit a text should be generated "click here" which will should open generated url in new window.
http://myurl.com/watch?v=**XYZ**&caption=**ABC**&link=**http://google.com**
The best option is to use JavaScript.
You can take your values from textfield on submit (check here) and create your url.
After you car redirect to your page using window.location
Ι created a page that makes that you want.
index.php
<html>
<head>
<title>My Page</title>
<script type="text/javascript">
function takevalues()
{
var value1 = document.getElementById('textfield1').value;
var value2 = document.getElementById('textfield2').value;
var value3 = document.getElementById('textfield3').value;
window.location = "http://myurl.com?value1="+value1+"&value2="+value2+"&value3="+value3;
}
</script>
</head>
<body>
<form name="myform" action="javascript:takevalues()" method="POST">
<div align="center">
<br><br>
<input type="text" size="25" id ="textfield1"> <br>
<input type="text" size="25" id ="textfield2"> <br>
<input type="text" size="25" id ="textfield3"> <br>
<br><br>
<input type="submit" size="value" id ="Submit">
</div>
</form>
</body>
</html>
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>