I have a VUE app posting to a PHP backend using PHPMailer for sending emails. In my local setup, the VUE frontend posts to PHP with no problem and emails are sending with content. Since migrating my code to a staging server, the frontend posts with no issue, emails are sending, but the emails are sending with no content. On form submission,formData
is logging the correct values so it does look like the data is being sent, just something on the PHP side not working quiet right.
I'm a bit confused as to why this might be happening. If anyone is able to point out an issue or a better way to achieve what i'm trying to do it would be appreciated.
Submit Method
methods: {
onSubmit() {
this.sending =! this.sending;
const formData = new FormData();
formData.append('winningUid', this.winningUid);
formData.append('name', this.form.name);
formData.append('email', this.form.email);
formData.append('address1', this.form.address1);
formData.append('address2', this.form.address2);
formData.append('city', this.form.city);
formData.append('county', this.form.county);
formData.append('postCode', this.form.postCode);
formData.append('mobileNumber', this.form.mobileNumber);
formData.append('deliveryInstructions', this.form.deliveryInstructions);
formData.append('sfu', this.form.sfu);
axios.post('/api', formData).then(res => {
console.log('SUCCESS', res.data);
this.mailSent = true;
this.data_captcher = false;
for (var pair of formData.entries()) {
console.log(pair[0]+ ', ' + pair[1]);
}
}).catch(err => {
console.log('ERROR', err);
});
}
}
Mailing Script
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once "vendor/autoload.php";
// PHPMailer Object
$mail = new PHPMailer(true);
// Test using SendGrid
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->Host = 'xxx';
$mail->Username = 'xxx';
$mail->Password = 'xxx';
// Vars
$uid = isset($_POST['winningUid']) ? $_POST['winningUid'] : '';
$name = isset($_POST['name']) ? $_POST['name'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$address1 = isset($_POST['address1']) ? $_POST['address1'] : '';
$address2 = isset($_POST['address2']) ? $_POST['address2'] : '';
$city = isset($_POST['city']) ? $_POST['city'] : '';
$county = isset($_POST['county']) ? $_POST['county'] : '';
$postCode = isset($_POST['postCode']) ? $_POST['postCode'] : '';
$mobileNumber = isset($_POST['mobileNumber']) ? $_POST['mobileNumber'] : '';
$deliveryInstructions = isset($_POST['deliveryInstructions']) ? $_POST['deliveryInstructions'] : '';
//From email address and name
$mail->From = '[email protected]';
$mail->FromName = $name;
//To address and name
$mail->addAddress("[email protected]", "To");
//Address to which recipient will reply
$mail->addReplyTo("[email protected]", "Reply");
$mail->isHTML(true);
$mail->Subject = 'Winning submission #' . $uid;
// Get required email template
$email_template = 'templates/default.html';
$template = file_get_contents($email_template);
// Build content variables
$template = str_replace('*|UID|*', $uid, $template);
$template = str_replace('*|FULLNAME|*', $name, $template);
$template = str_replace('*|EMAIL|*', $email, $template);
$template = str_replace('*|ADDRESS1|*', $address1, $template);
$template = str_replace('*|ADDRESS2|*', $address2, $template);
$template = str_replace('*|CITY|*', $city, $template);
$template = str_replace('*|COUNTY|*', $county, $template);
$template = str_replace('*|POSTCODE|*', $postCode, $template);
$template = str_replace('*|MOBILENUMBER|*', $mobileNumber, $template);
$template = str_replace('*|DELIVERYINSTRUCTIONS|*', $deliveryInstructions, $template);
$mail->MsgHTML($template);
try {
$mail->send();
echo "Message has been sent successfully";
} catch (Exception $e) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.