Hope some PHP gurus can help me out with this. I am creating a simple donation form to accept payments using Stripe. I have included my code here. The form works fine in terms of processing payments. However, the script is supposed to send a confirmation email to the donor, saying that their donation has been received, etc. The issue I am having is that the script does not send such a confirmation. I am using GoDaddy hosting and have checked that my MX records are correct. I ran test from my hosting account (with help of GoDaddy support) as well to see if there's any issue with the account itself. The tests showed no such issues. I have tried minor tweaks such as changing headers, adding <>, etc., but no luck.
Here's my code for config.php
<?php
return array(
'test-mode' => true,
'secret-key' => 'YOUR_SECRET_KEY',
'publishable-key' => 'YOUR_PUBLISHABLE_KEY',
'thank-you' => 'http://example.com/thank-you.html',
'email-from' => 'no-reply#example.com',
'email-bcc' => 'admin#example.com',
'email-subject' => 'Thank you for your donation!',
'email-message' => "Dear %name%,\n\nThank you for your order of %amount%."
);
Here's my code for index.php
<?php
require('lib/Stripe.php');
$config = require('config.php');
if ($config['test-mode'] && $_SERVER['HTTPS'] != 'on') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit;
}
if ($_POST) {
Stripe::setApiKey($config['secret-key']);
$token = $_POST['stripeToken'];
$first_name = $_POST['first-name'];
$last_name = $_POST['last-name'];
$name = $first_name . ' ' . $last_name;
$address = $_POST['address'] . "\n" . $_POST['city'] . ', ' . $_POST['state'] . ' ' . $_POST['zip'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$amount = (float) $_POST['amount'];
try {
if ( ! isset($_POST['stripeToken']) ) {
throw new Exception("The Stripe Token was not generated correctly");
}
// Charge the card
$donation = Stripe_Charge::create(array(
'card' => $token,
'description' => 'Donation by ' . $name . ' (' . $email . ')',
'amount' => $amount * 100,
'currency' => 'usd'
));
// Build and send the email
$headers = 'From: ' . $config['emaily-from'];
$headers .= "\r\nBcc: " . $config['emaily-bcc'] . "\r\n\r\n";
// Find and replace values
$find = array('%name%', '%amount%');
$replace = array($name, '$' . $amount);
$message = str_replace($find, $replace , $config['email-message']) . "\n\n";
$message .= 'Amount: $' . $amount . "\n";
$message .= 'Address: ' . $address . "\n";
$message .= 'Phone: ' . $phone . "\n";
$message .= 'Email: ' . $email . "\n";
$message .= 'Date: ' . date('M j, Y, g:ia', $donation['created']) . "\n";
$message .= 'Transaction ID: ' . $donation['id'] . "\n\n\n";
$subject = $config['email-subject'];
// Send it
if ( !$config['test-mode'] ) {
mail($email,$subject,$message,$headers);
}
// Forward to "Thank You" page
header('Location: ' . $config['thank-you']);
exit;
} catch (Exception $e) {
$error = $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stripe Payment Form</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all">
<script type="text/javascript" src="https://js.stripe.com/v2"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
Stripe.setPublishableKey('<?php echo $config['publishable-key'] ?>');
</script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div class="wrapper">
<h1>Stripe Payment Form</h1>
<p><strong>Thanks for donating!</strong></p>
<div class="messages">
<!-- Error messages go here go here -->
</div>
<form action="#" method="POST" class="donation-form">
<fieldset>
<legend>
Contact Information
</legend>
<div class="form-row form-first-name">
<label>First Name</label>
<input type="text" name="first-name" class="first-name text">
</div>
<div class="form-row form-last-name">
<label>Last Name</label>
<input type="text" name="last-name" class="last-name text">
</div>
<div class="form-row form-email">
<label>Email</label>
<input type="text" name="email" class="email text">
</div>
<div class="form-row form-phone">
<label>Phone</label>
<input type="text" name="phone" class="phone text">
</div>
<div class="form-row form-address">
<label>Address</label>
<textarea name="address" cols="30" rows="2" class="address text"></textarea>
</div>
<div class="form-row form-city">
<label>City</label>
<input type="text" name="city" class="city text">
</div>
<div class="form-row form-state">
<label>State</label>
<select name="state" class="state text">
<option value="AL">AL</option>
<option value="WY">WY</option>
</select>
</div>
<div class="form-row form-zip">
<label>Zip</label>
<input type="text" name="zip" class="zip text">
</div>
</fieldset>
<fieldset>
<legend>
Your Generous Donation
</legend>
<div class="form-row form-amount">
<label><input type="radio" name="amount" class="set- amount" value="25"> $25</label>
<label><input type="radio" name="amount" class="set-amount" value="100"> $100</label>
<label><input type="radio" name="amount" class="other-amount" value="0"> Other:</label> <input type="text" class="amount text" disabled>
</div>
<div class="form-row form-number">
<label>Card Number</label>
<input type="text" autocomplete="off" class="card-number text" value="4242424242424242">
</div>
<div class="form-row form-cvc">
<label>CVC</label>
<input type="text" autocomplete="off" class="card-cvc text" value="123">
</div>
<div class="form-row form-expiry">
<label>Expiration Date</label>
<select class="card-expiry-month text">
<option value="01" selected>January</option>
<option value="12">December</option>
</select>
<select class="card-expiry-year text">
<option value="2017" selected>2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
</select>
</div>
<div class="form-row form-submit">
<input type="submit" class="submit-button" value="Submit Donation">
</div>
</fieldset>
</form>
</div>
<script>if (window.Stripe) $('.donation-form').show()</script>
<noscript><p>JavaScript is required for the donation form.</p></noscript>
</body>
</html>
Any help is greatly appreciated.
Related
So I have a problem in my CRUD application using Node JS, Express, and Mongo DB. Actually, I am just following this tutorial but I get stuck on the UPDATE part. I am able to CREATE, READ, and DELETE values from database already, but I don't know why I keep getting this error whenever I try to UPDATE my data.
I found the error is from my controller.js file and here's the code:
exports.update = (req,res)=>{
if(!req.body){
return res
.status(400)
.send({message:"Record to be updated can not be empty!"})
}
const id = req.params.id;
studentDb.findByIdAndUpdate(id,req.body,{userFindAndModify:false})
.then(data=>{
if(!data){
res.status(404).send({message:`Cannot update student record with ID ${id}. Maybe record not found.`})
}else{
res.send(data)
}
})
.catch(err=>{
res.status(500).send({message:`Error in updating student record with id=${id}.` + err})
})
}
My hypothesis is that the objectID goes on the first model in my schema because whenever I check the console when I run the application, the last value of the model in my schema, the "contact" goes undefined.
The ERROR:
I can provide the other codes related to this if my question is still unclear. Thank you in advance for answering! I've been stuck here for hours already.
EDIT
Here's the additional front-end code
(this is the FORM part from my update_student.ejs where I update the data):
<!-- form handling -->
<form method="POST" id="update_student">
<div class="new_student">
<div class="form-group">
<div class="row">
<div class="col-lg-4">
<label for="firstName" class="text-muted">First Name</label><br>
<input type="hidden" name="id" value="<%=students._id%>">
<input type="text" name="firstName" value="<%=students.firstName%>" placeholder="Corki">
</div>
<div class="col-lg-4">
<label for="middleName" class="text-muted">Middle Name</label><br>
<input type="text" name="middleName" value="<%=students.middleName%>" placeholder="Vi">
</div>
<div class="col-lg-4">
<label for="lastName" class="text-muted">Last Name</label><br>
<input type="text" name="lastName" value="<%=students.lastName%>" placeholder="Fortune">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-4">
<label for="gender" class="text-muted">Gender</label><br>
<div class="radio inline">
<input type="radio" id="radio-2" name="gender" value="Male" <% if(students.gender == "Male"){ %>checked <% } %>>
<label for="radio-2" class="radio-label">Male</label>
</div>
<div class="radio inline">
<input type="radio"id="radio-3" name="gender" value="Female" <% if(students.gender == "Female"){ %>checked <% } %>>
<label for="radio-3" class="radio-label">Female</label>
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label for="birthday" class="text-muted">Birthday</label>
<input type="text" name="birthday" value="<%=students.birthday%>" placeholder="MM/DD/YYYY">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-6">
<label for="program" class="text-muted">Program</label>
<input type="text" name="program" value="<%=students.program%>" placeholder="i.e. BSIT">
</div>
<div class="col-md-6">
<label for="yearLevel" class="text-muted">Year Level</label>
<select class="form-select" name="yearLevel">
<option value="">Select year level</option>
<option <% if(students.yearLevel == "First Year"){ %>selected <% } %> value="First Year">First Year</option>
<option <% if(students.yearLevel == "Second Year"){ %>selected <% } %> value="Second Year">Second Year</option>
<option <% if(students.yearLevel == "Third Year"){ %>selected <% } %> value="Third Year">Third Year</option>
<option <% if(students.yearLevel == "Fourth Year"){ %>selected <% } %> value="Fourth Year">Fourth Year</option>
<option <% if(students.yearLevel == "Fifth Year"){ %>selected <% } %> value="Fifth Year">Fifth Year</option>
<option <% if(students.yearLevel == "Masteral"){ %>selected <% } %> value="Masteral">Masteral</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="email" class="text-muted">Email</label>
<input type="text" name="email" value="<%=students.email%>" placeholder="example#gmail.com">
</div>
<div class="form-group">
<label for="address" class="text-muted">Address</label>
<input type="text" name="address" value="<%=students.address%>" placeholder="Household No., Barangay, City, Province">
</div>
<div class="form-group">
<label for="contact" class="text-muted">Contact</label>
<input type="text" name="contact" value="<%=students.contact%>" placeholder="i.e 09XX-XXX-XXXX">
</div>
<div class="form-group">
<button type="submit" class="btn text-dark update">Save</button>
</div>
</div>
</form>
<!-- form handling -->
Code for my #update_student JS just in case:
$('#update_student').on("submit",(function(event){
event.preventDefault();
var unindexed_array = $(this).serializeArray();
var data = {}
$.map(unindexed_array,function(n,i){
data[n['firstName']] = n['value']
})
console.log(data);
var request={
"url": `http://localhost:1485/api/students/${data.id}`,
"method":"PUT",
"data" : data
}
$.ajax(request).done(function(response){
alert("Data updated successfully!");
})
}))
Thanks to Sir #Rajdeep Debnath 's help, I was able to look into may "unindexed_array" from my console.log and figured out that instead of data[n['firstName']] = n['value']
I should write data[n['name']] = n['value']
I wrote the former because I thought it is just the name of the variable but in actuality, it is like the "id" or "class" called in JavaScript. The form used "name" on the inputs (like <input type="text" name="program" value="<%=students.program%>" placeholder="i.e. BSIT"> from my code) so that's why it is the one called in the function instead.
Now my code for my #update_student JS goes like this:
$('#update_student').on("submit",(function(event){
event.preventDefault();
var unindexed_array = $(this).serializeArray();
var data = {}
$.map(unindexed_array,function(n,i){
data[n['name']] = n['value']
})
console.log(data);
var request={
"url": `http://localhost:1485/api/students/${data.id}`,
"method":"PUT",
"data" : data
}
$.ajax(request).done(function(response){
alert("Data updated successfully!");
})
}))
You just simply change your Url path with ``symbol instead of ''.
Just like that
var request={
"url": `http://localhost:1485/api/students/${data.id}`,
"method":"PUT",
"data" : data
}
I have view
<!-- input-text -->
<div class="form-group">
<?php $name = 'name';
$placeholder = 'Nama Lengkap';
$value = old($name); ?>
<label for="<?= $name; ?>"><?= $placeholder; ?></label>
<input type="text" class="form-control <?= ($validation->hasError($name)) ? "is-invalid" : ''; ?>" id="<?= $name; ?>" name="<?= $name; ?>" placeholder="<?= $placeholder; ?>" value="<?= $value ?>">
<div class="invalid-feedback">
<?= $validation->getError($name); ?>
</div>
</div>
<!-- input-select -->
<div class="form-group">
<?php $name = 'gender';
$placeholder = 'Jenis Kelamin';
$value = old($name); ?>
<label for="<?= $name; ?>"><?= $placeholder; ?></label>
<select name="<?= $name; ?>" class="selectpicker form-control" data-live-search="true" id="<?= $name; ?>">
<option value="0">Laki-laki</option>
<option value="1">Perempuan</option>
</select>
</div>
and controller
public function create(){
dd($this->request->getVar());}
it show only name, but gender doesn't. How to show the value of selected option in CodeIgniter 4?
when you try to catch your post in controller u should type the name variable of the input
public function create(){
dd($this->request->getVar('gender'));
}
Use form helper, try it:
<div class="form-group">
<label for="name">Nama Lengkap</label>
<?php echo form_input('name', set_value('name'), 'class="form-control" placeholder="Nama Lengkap"'); ?>
<?php if(!empty($errors)){ ?>
<em class="text-danger"><?php echo $errors->getError('name') ?></em>
<?php } ?>
</div>
<div class="form-group">
<label for="gender">Jenis Kelamin</label>
<?php echo form_dropdown('gender', ['0' => 'Laki-laki', '1' => 'Perempuan'], [], 'class="form-control"'); ?>
</div>
Hope it helpful, cheers...
in pop up box, we are displaying login form. once user enter wrong email id or password, we are displaying message : Invalid login/pw , but once they enter correct details and click on login button, than user will be logged in.
but issue is pop up box will remain until we close the pop up manually with help of close button as in below image, but i want to hide the pop up box if login is successfull.
enter image description here
Once we click on login, under Response tab, if there is no message, than i want to hide the pop up, if there is message as success":false,"error":"Invalid login or password." , than i don't want to hide the pop up
enter image description here
I tried below code :
Html
<form>
//code for email and pw
<button onclick = "hideWindow()">Login</button>
</form>
Ajax
function hideWindow()
{
var username=jQuery( "#customusername" ).val();
var password=jQuery( "#custompassword" ).val();
url="";
new Ajax.Request(url, {
method: 'POST',
onFailure: function(response){
},
parameters: {
username: username,
password:password
},
onSuccess: function(response)
{
if(response.responseText=="")
{
//trigger to close popup
document.getElementById('something').style.display = 'none';
document.getElementById('ajaxlogin-mask').style.display = 'none';
}
}
});
}
edit
<div class="ajaxlogin-window" id="something">
<form>
<div class="content">
<ul class="form-list">
<li>
<input type="hidden" id="likeproduct_id" name="product_id" value=""/>
<label for="email" class="required"><em>*</em>Email</label>
<div class="input-box">
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" title="<?php echo $this->__('Email Address') ?>" />
</div>
</li>
<li>
<label for="pass" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
<div class="input-box">
<input type="password" name="login[password]" id="pass" title="<?php echo $this->__('Password') ?>" />
</div>
</li>
<?php echo $this->getChildHtml('form.additional.info'); ?>
</ul>
</div>
<div class="buttons-set">
<button onclick = "hideWindow()" type="submit" class="button" title="<?php echo $this->__('Login') ?>" name="send" id="send2" ><span><span><?php echo $this->__('Login') ?></span></span></button>
</div>
</div>
As I can see there is some thing wrong with your ajax function try this out:
onSuccess: function(response)
{
document.getElementById('something').style.display = 'none';
document.getElementById('ajaxlogin-mask').style.display = 'none';
}
function hideWindow()
{
var db_username = 'ankit';
var db_password = 'password';
var username=jQuery( "#customusername" ).val();
var password=jQuery( "#custompassword" ).val();
if(username = db_username && password == db_password) {
jQuery('#something').hide();
}
else{
jQuery('#something').prepend('Wrong Cred ');
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ajaxlogin-window" id="something">
<form>
<div class="content">
<ul class="form-list">
<li>
<input type="hidden" id="likeproduct_id" name="product_id" value=""/>
<label for="email" class="required"><em>*</em>Email</label>
<div class="input-box">
<input type="text" name="login[username]" value="" id="email" title="Email Address" />
</div>
</li>
<li>
<label for="pass" class="required"><em>*</em>Password</label>
<div class="input-box">
<input type="password" name="login[password]" id="pass" title="Password" />
</div>
</li>
</ul>
</div>
<div class="buttons-set">
<button onclick = "hideWindow()" type="submit" class="button" title="Login" name="send" id="send2" ><span><span>Login</span></span></button>
</div>
Please check the code instead of ajax call i have just added a if condition.
Hope it might help you
Thanks
I am trying to update the records form a table by using Sequelize.
Unfortunately, the id of the event I am trying to update seems to be undefined. How can I send it correctly?
The block of code I have in my controller looks like this:
router.get('/edit/:eventid', function(req, res) {
var eventid = req.params.eventid;
Event.findById(req.params.eventid).then(function(event) {
eventid= event.eventid;
title= event.title;
description= event.description;
availabletickets=event.availabletickets;
date= event.date;
newDate= date.toString();
newdate= newDate.substring(0,21);
console.log(eventid);
}) .then(function() {
res.render('eventEdit', {
eventid: eventid,
pagetitle: ' Edit Event',
title: title,
description:description,
availabletickets:availabletickets,
newdate: newdate,
});
})
.catch(function(error) {
res.render('error', {
error: error
});
});
});
router.post('/edit', function(req, res){
var eventid = req.body.eventid;
var title = req.body.title;
var description = req.body.description;
var availabletickets= req.body.availabletickets;
var date = req.body.date;
console.log( eventid); //this returns undefined.
console.log('title, description, availabletickets, date);
const newData = {
title: title,
date: date,
description: description,
availabletickets: availabletickets
};
Event.update(
newData,
{
where:{
eventid:eventid
}
}
).then(function() {
console.log("Event updated");
res.redirect('/events');
}).catch(e => console.error(e));
});
Although, the HTML file,where the user introduces the values when editing the events, looks like this:
<div class="container">
<h2><%= pagetitle %> </h2>
<form method="post" action="/events/edit">
<div class="container">
<div class="col-md-12 ">
<div class="row">
<div class="col-md-12 ">
<input class="form-control" type="text" name="title" id="title" value="<%= title %>" placeholder="Titlu Eveniment" required="true">
<p style="color:#8B0000;"><small>*This field is mandatory</small></p>
<textarea rows=7 class="form-control" type="text" name="description" id="description" placeholder="Descriere Eveniment"><%= description %></textarea> <br>
<input class="form-control" type="text" name="availabletickets" id="availabletickets" value="<%= availabletickets %>"> <br>
<label> Data:<%= newdate %> </label> <br/>
<label>Cahnge event date:</label>
<input class="form-control" type="date" name="date" id="date" style="width:190px;" ><br>
<button class="btn" id="addValue" style="background-color:#8B0000; color:white;">Save</button>
<button class="btn btn-warning">Cancel</button>
</div>
</div>
</div>
</div>
</form>
</div>
You get the eventid as undefined because req.body doesn't contain the eventid (it's not passed from the client side). To pass it from the client side you have to add an input having the name="eventid" attribute.
In the EJS template you need to render the eventid value as a hidden input (<input type="hidden" ...)
You can do that by added in your form this line:
<input type="hidden" value="<%= eventid %>" name="eventid" />
This is the updated form code:
<div class="container">
<h2><%= pagetitle %> </h2>
<form method="post" action="/events/edit">
<input type="hidden" value="<%= eventid %>" name="eventid" />
<div class="container">
<div class="col-md-12 ">
<div class="row">
<div class="col-md-12 ">
<input class="form-control" type="text" name="title" id="title" value="<%= title %>" placeholder="Titlu Eveniment" required="true">
<p style="color:#8B0000;"><small>*This field is mandatory</small></p>
<textarea rows=7 class="form-control" type="text" name="description" id="description" placeholder="Descriere Eveniment">
<%= description %>
</textarea>
<br>
<input class="form-control" type="text" name="availabletickets" id="availabletickets" value="<%= availabletickets %>">
<br>
<label> Data:
<%= newdate %>
</label>
<br/>
<label>Cahnge event date:</label>
<input class="form-control" type="date" name="date" id="date" style="width:190px;">
<br>
<button class="btn" id="addValue" style="background-color:#8B0000; color:white;">Save</button>
<button class="btn btn-warning">Cancel</button>
</div>
</div>
</div>
</div>
</form>
</div>
I am trying to set the "to" address for an email sent via an html form utilizing phpmailer. The end goal is to utilize a droplist to let the user select which person they are contacting depending on their needs. However, as I don't know much about PHP I'm going step by step and am already stuck.
I'm using the example that came with the site I purchased, but trying to modify it to include a to field. Right now I'm simply trying to get a new variable to show up but have not succeeded. This is the HTML form I have in place right now:
<form name="contact" method="post" action="phpmailer.php" class="af-form" id="af-form">
<div class="af-outer af-required">
<div class="af-inner">
<label for="toemail" id="toemail_label">To Whom:</label>
<input type="text" name="toemail" id="toemail" size="30" value="" class="text-input span8"/>
<label class="error" for="toemail" id="toemail_error">To field is required.</label>
</div>
</div>
<div class="af-outer af-required">
<div class="af-inner">
<label for="name" id="name_label">Your Name:</label>
<input type="text" name="name" id="name" size="30" value="" class="text-input span8"/>
<label class="error" for="name" id="name_error">Name is required.</label>
</div>
</div>
<div class="af-outer af-required">
<div class="af-inner">
<label for="email" id="email_label">Your Email:</label>
<input type="text" name="email" id="email" size="30" value="" class="text-input span8"/>
<label class="error" for="email" id="email_error">Email is required.</label>
</div>
</div>
<div class="af-outer af-required">
<div class="af-inner">
<label for="input-message" id="message_label">Your Message:</label>
<textarea name="message" id="input-message" cols="30" class="text-input span8"></textarea>
<label class="error" for="input-message" id="message_error">Message is required.</label>
</div>
</div>
<div class="af-outer af-required">
<div class="af-inner">
<input type="submit" name="submit" class="form-button btn btn-large" id="submit_btn" value="Send Message!" />
</div>
</div>
The name, email, and message fields get picked up fine and populate in the email I recieve. However, the "toemail" field doesn't show up. Here is the process.php I am using for phpmailer.
<?php
if ((isset($_POST['toemail'])) && (strlen(trim($_POST['toemail'])) > 0)) {
$toemail = stripslashes(strip_tags($_POST['toemail']));
} else {$toemail = 'No to address entered';}
if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) {
$name = stripslashes(strip_tags($_POST['name']));
} else {$name = 'No name entered';}
if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) {
$email = stripslashes(strip_tags($_POST['email']));
} else {$email = 'No email entered';}
if ((isset($_POST['message'])) && (strlen(trim($_POST['message'])) > 0)) {
$message = stripslashes(strip_tags($_POST['message']));
} else {$message = 'No phone entered';}
ob_start();d
?>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<table width="550" border="1" cellspacing="2" cellpadding="2">
<tr bgcolor="#eeffee">
<td>To Whom:</td>
<td><?=$toemail;?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Name</td>
<td><?=$name;?></td>
</tr>
<tr bgcolor="#eeeeff">
<td>Email</td>
<td><?=$email;?></td>
</tr>
<tr bgcolor="#eeffee">
<td>Message</td>
<td><?=$message;?></td>
</tr>
</table>
</body>
</html>
<?
$body = ob_get_contents();
$to = 'personalemailtousefortesting.com';
$email = 'email#example.com';
$fromaddress = "you#example.com";
$fromname = "Online Contact";
require("phpmailer.php");
$mail = new PHPMailer();
$mail->From = "mail#yourdomain.com";
$mail->FromName = "Contact Form";
$mail->AddAddress("mypersonalemailfortestingpurposes#gmail.com","Name 1"); // addresses here
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Contact form submitted";
$mail->Body = $body;
$mail->AltBody = "This is the text-only body";
if(!$mail->Send()) {
$recipient = 'mypersonalemailfortestingpurposes#gmail.com';
$subject = 'Contact form failed';
$content = $body;
mail($recipient, $subject, $content, "From: mail#yourdomain.com\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
exit;
}
?>
The email I get populates the name, email, and message fields fine, however, I get my fall back error message of 'No to address entered' for the "toemail" input.
This is issue number one. I'll post the phpmailer.php that I'm using if anyone needs to see it. I do not know if I need to define the variable in there first.
After I get that working, I need to make it work for a dropdown list so the user cannot just send the email to whomever they would like.
THEN, I need to set that as the actual send-to address. I do not know how to set the actual address for sending purposes. I would assume that I change
$mail->AddAddress("mypersonalemailfortestingpurposes#gmail.com","Name 1"); // addresses here
to something like...
$mail->AddAddress($toemail,"Name 1"); // addresses here
...but odds are that's not correct.
Any help you can provide would be wonderful.
If you need to see my phpmailer.php I can post that too.
Thanks again,
-Rocky Colt TumTum
Just incase you didn't find this, this is what was listed on the PHP Manual site.
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>