I want to send email by clicking on button using aframe. I did something but that does not work. Here is working flow.
I have database and I am getting user email form database.
Here is html:
<a-plane id="information-button" name="button-press" class="clickable"
position="6 -4.845 3" rotation="0 -30 0" width="3" height="1" color="#000">
<a-text value="More Info" position="-0.946 0.077 0.349" scale="2 2 2">
</a-text>
</a-plane>
Here is email.php to send the email.
<?php
include('server.php');
session_start();
?>
<?php
if (isset($_POST['button-press'])) {
require "PHPMailer/src/PHPMailer.php";
require "PHPMailer/src/OAuth.php";
require "PHPMailer/src/SMTP.php";
require "PHPMailer/src/POP3.php";
require "PHPMailer/src/Exception.php";
require 'PHPMailer/src/PHPMailerAutoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
if (isset($_SESSION['email'])){
$headers = "MIME-Version: 1.0" . '\r\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1' . '\r\n';
$message = '<p><strong>You are in.</strong></p>';
$subj = 'More Information';
$to = 'falak#oddly.co';
$from = 'falaksabbir3#gmail.com';
define('GUSER', 'falaksabbir3#gmail.com'); // GMail username
define('GPWD', '******');
define('SMTPUSER', 'falaksabbir3#gmail.com'); // sec. smtp username
define('SMTPPWD', '******'); // sec. password
define('SMTPSERVER', 'smtp.gmail.com'); // sec. smtp server
//send mail
if ( smtpmailer($to, $from, $name, $subj, $message,$headers)){
echo 'Message send via Gmail';
} else {
if (!smtpmailer($to, $from, $name, $subj, $message,$headers)){
if (!empty($error)) echo $error;
} else {
echo 'Yep, the message is send (after doing some hard work)';
}
}
//send email function
function smtpmailer($to, $from, $from_name, $subject, $body, $is_gmail = true) {
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
if ($is_gmail) {
$mail->SMTPSecure = 'ssl';
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
}
else {
$mail->Host = SMTPSERVER;
$mail->Username = SMTPUSER;
$mail->Password = SMTPPWD;
}
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->IsHTML(true);
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
}}
?>
So this is how I did. Can I do php with aframe? Or any guidelines with this.
Yes you can do PHP with A-Frame.
Currently though your A-Frame code does not interact with your PHP code. You want your action (in VR or not) to call the server. I suggest to :
make the send action work by just visiting the page
make sure it works without VR, for example using a simple HTML button How to Call a PHP Function on the Click of a Button
finally make it work with VR and A-Frame probably using the cursor and a bit of JavaScript https://aframe.io/docs/0.8.0/components/cursor.html#example
Related
I'm creating a form that sends an email to the email that was entered into it. I have installed PHP mailer on my server.
Currently when sending emails via PHP they send like this:
All emails sent are via the hosting server when I'd like them to look like this.
Just like any other email sent on the domain they should be mailed by domain.com rather than the server.
I'm just testing this so using a simple form as a proof of concept.
<form method="post" name="process.php" action="process.php">
<p>Name:</p><br><input type="text" name="name"><br><br>
<p>Email Address:</p><br><input type="text" name="email"><br><br>
<br>
<input type="submit" value="Send Email">
</form>
I'm then using this PHP to send the email:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'noreply#domain.com';
$mail->Password = 'password';
$email_from = "noreply#domain.com";
$email_subject = "Test Email";
$to = $email;
$headers = "From: noreply#domain.com \r\n";
$headers .= "Bcc: noreply#domain.com \r\n";
$headers .= "Reply-To: me#domain.com \r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$email_body = <<<EOM
<p color="#000000">Hello, $name.<br><br> This is a test email for mailing from the domain rather than the server.<br><br> </p>
EOM
;
mail($to, $email_subject, $email_body, $headers);
?>
Basically, I want PHP emails mailed by my domain and I don't know how to do this so any help would be appreciated, my web host doesn't seem able to help me with this.
Thanks in advance.
UPDATE
This code for the form.
<h1>The email gets sent to a bookings address.</h1>
<form method="post" name="process.php" action="process.php">
<p class= "whitetextsubsmall">Name:</p><br><input type="text" name="name"><br><br>
<p class= "whitetextsubsmall">Email Address:</p><br><input type="text" name="email"><br><br>
<br>
<input type="submit" value="Send Email">
</form>
And this code for process.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'noreply#domain.com'; /* This is the sender of the bookings. */
$mail->Password = 'password';
$mail->setFrom('noreply#domain.com');
$mail->addAddress('bookings#domain.com', 'Company Bookings');
$mail->addReplyTo($email, $name); /* Reply to the user who submitted the form from the bookings email. */
$mail->Subject = 'Booking Request Test';
$mail->isHTML(TRUE);
$mail->Body = 'Message test <br> Booking Request from: $name <br><br> Email: $email.';
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
You are mixing the PHPMailer syntax with PHP mail() syntax.
For the PHPMailer, use the following in your code.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'noreply#domain.com';
$mail->Password = 'password';
/* Set the mail sender. */
$mail->setFrom($email, $name);
/* Add a recipient. */
$mail->addAddress('noreply#domain.com', 'earningtoanimate');
/* Add a replyto. */
$mail->addReplyTo($email, $name);
/* Add a CC and Bcc. */
$mail->addCC('noreply2#domain.com', 'earningtoanimate2');
$mail->addBCC('noreply3#domain.com', 'earningtoanimate3');
/* Add email subject. */
$mail->Subject = 'Test Email';
/* Add email body. */
$mail->isHTML(TRUE);
$mail->Body = 'There goes your message.';
/* Finally send the mail. */
if(!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
Test the above and give your feedback. Note, I didn't test code. Just wrote them here so it's possible to have some edits if need be.
For further reading visit PHPMailer documentation
Currentlt it shows the mail on which phpmailer SMTP is registered.
$email='abc#email.com';
$subjectRsc="Any";
$message='Welcome';
phpmail($email, $subjectRsc, $message);
My phpmailer function:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Debugoutput = 'html';
$mail->Host = 'smptp';
$mail->Port = 465; // or 587
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->SMTPAuth = true;
$mail->Username = PHP_MAILER_EMAIL;
$mail->Password = PHP_MAILER_PASSWORD;
$mail->AddReplyTo(REPLY_EMAIL, 'ABC');
$mail->SetFrom(FROM_EMAIL, 'ABC');
$mail->Subject = $subject;
$address = $to;
$mail->AddAddress($address);
$mail->MsgHTML($message);
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
return true;
}
This is how I am sending mails to the users I want to show the specific mail of my website to be displayed in the mails not that on which smtp server is registered.
You should try this :
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Debugoutput = 'html';
$mail->Host = 'smptp';
$mail->Port = 465; // or 587
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->SMTPAuth = true;
$mail->Username = PHP_MAILER_EMAIL;
$mail->Password = PHP_MAILER_PASSWORD;
$mail->addReplyTo('myemail#example.com', 'ABC'); //<-- this is the line i changed
$mail->From= "myemail#example.com"; //<-- this is the line i changed
$mail->Subject = $subject;
$address = $to;
$mail->AddAddress($address);
$mail->MsgHTML($message);
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
return true;
}
According to phpmailer documentation this is the field to add the sender's email.
please try using this code :
<?php
require_once "vendor/autoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "from#yourdomain.com";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("test#gmail.com", "Test");
$mail->addAddress("test1#gmail.com");
//Address to which recipient will reply
//if you want to add CC and BCC
$mail->addCC("cc#example.com");
$mail->addBCC("bcc#example.com");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
?>
Please try using this code:
<?php
$to = "test#gmail.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:test1#gmail.com \r\n";
$header .= "Cc:test2#gmail \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I trying to send an email from php using php mail() function.
Each time when I try to send an email it displays the error message.I don't know what went wrong.Here is my code. Can anyone tell me what went wrong ?
$message = "<html><body>";
$message .= "<table rules='all'>";
$message .= "<tr><td><strong>Name: Ramya</strong> </td></tr>";
$message .= "<tr><td><strong>Email: ramyaroy</strong> </td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$to = 'ramya#example.com';
$email='vinay#example.net';
$subject = 'Website Change Reqest';
$headers = "From:".$email.PHP_EOL;
$headers .= "Reply-To:".$email.PHP_EOL;
$headers .= "MIME-Version: 1.0".PHP_EOL;
$headers .= "Content-Type: text/html; charset=ISO-8859-1".PHP_EOL;
if (mail($to, $subject, $message, $headers)) {
echo 'Your message has been sent.';
} else {
echo 'There was a problem sending the email.';
}
There's no error in the code.
The problem could be because of your hosting. Usually, hosting account will allow to send a mail from only that domain account.
Change the $email to vinay#[your_domain_name].com
Let me know after you try this.
<?php
/*
Below code works on live and local both server , also on SSL
which I describe all options on comments
you need to set SMTP server username and password ,
this is same as your google email id and password
*/
/* You need to download php-mailer class
https://github.com/PHPMailer/PHPMailer */
define('SMTP_USERNAME','your smtp username');
define('SMTP_PASSWORD','password');
define('FROM_EMAIL','from email');
define('ADMIN_EMAIL','replay to email');
define('SITE_NM','your site name');
print_r(sendEmail('john.doe#gmail.com','Lorem Ipsum','anything....'));
function sendEmail($to, $subject, $message) {
require_once("class.phpmailer.php");
// create a new object
$mail = new PHPMailer();
// enable SMTP
$mail->IsSMTP();
// debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPDebug = 0;
// authentication enabled
$mail->SMTPAuth = true;
//mail via gmail
//$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
//$mail->Host = "smtp.gmail.com";
//$mail->Port = 465; // or 587
//mail via hosting server
$mail->Host = SMTP_HOST;
if (SMTP_HOST == 'smtp.gmail.com') {
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Port = 465; // or 58
}else{
$mail->Port = 587; // or 58
}
$mail->IsHTML(true);
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
//$mail->SetFrom(SMTP_USERNAME);
$mail->SetFrom(FROM_EMAIL);
$mail->AddReplyTo(ADMIN_EMAIL, SITE_NM);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AddAddress($to);
// to add bcc mail list
$mail->AddBCC("example#gmail.com", "your name");
$mail->AddBCC("example2#gmail.com", "XXX XXXXX");
$result = true;
if (!$mail->Send()) {
//echo "Mailer Error: " . $mail->ErrorInfo;
$result = false;
}
return $result;
}
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I am using mail() function to sent mails when an event happening. But it is not working as I expected. I tried to get the return of the function also. Some one please suggst what may be the issue.
$msg = "Your password has been changed.is'".$data['password']."'";
$to = $data['email'];
$subject = "password changed";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: info#hia.com';
$send = mail($to, $subject, $msg, $headers);
if($send){
echo "successful";
}
else{
echo "error";
}
Problems arising from the php setting. Closing function for security by some service provider. You must send mail with SMTP.
Example several SMTP class on github;
hujuice/smtp - snipworks/php-smtp - PHPMailer/PHPMailer
Example code a PHPMailer according to your code;
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info#hia.com'; // SMTP username
$mail->Password = 'yourmailpassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('info#hia.com', 'Mailer');
$mail->addAddress($data['email']); // Name is optional
$mail->addReplyTo('info#hia.com', 'Information');
$mail->addCC('cc#hia.com');
$mail->addBCC('bcc#hia.com');
$mail->CharSet = 'ISO-8859-1';
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'password changed';
$mail->Body = 'Your password has been changed.is "'.$data['password'].'"';
if(!$mail->send()) {
echo 'error';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'successful';
}
Don't use simple mail(), i prefer for PHPmailer function.
Here is a Example.
First - download phpmailer in your project directory.
second - create send_mail.php in your directory(you can change you name).
send_mail.php file code.
require_once "PHPMailer/PHPMailerAutoload.php";
$mail = new PHPMailer(true);
if (!isset($_POST['send'])) {
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the enquiry form!";
die;
}
$to="abc#xyz.com";
$senderName = "xyz";
//send the mail
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$zcode = $_POST["zcode"];
$email = $_POST["email"];
$phone = $_POST["phone"];
//Enable SMTP debugging.
$mail->SMTPDebug = 0;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "abc#xyz.com";
$mail->Password = "########";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "ssl";
//Set TCP port to connect to
$mail->Port = 465;
$mail->From = $to;
$mail->FromName = $senderName;
$mail->addAddress($to, $senderName);
$mail->addReplyTo($email, $name);
$mail->isHTML(true);
$mail->Subject = "bfuiebfiaif";
$mail->Body = "as per your needs";
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
die;
}
header('Location: index.php');
die;
I have a form on my website where people can join events. The code behind it works in this way:
All info is saved in a database. This part works fine.
The second part of the code send out an email to me and to the user with the info he entered (same info as saved in the database)
The issue is that these emails are sent unauthenticated through a default email on the hosting account. I had to modify the script to force SMTP authentication with a valid email under my hosting account to fix the error. Right now the script sends out the email but it ends in spamfilter with all ISPs so the user never receive the email.
I have no idea of how to do, or create the codes so the script use SMTP authentication. Below is the codes I have so fare. Can someone help me?
<?
// SEND OUT EMAIL PART
// COPY SEND TO MY SELF
$to = "my#email.com";
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Thanks!";
$fields = array();
$fields{"name"} = "Name";
$fields{"address"} = "Address";
$fields{"phone"} = "Phone";
$fields{"email"} = "E-mail addesse";
$body = "INFO:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
// SEND TO THE USER
$headers2 = "From: my#email.com";
$subject2 = "THANKS!";
$fields2 = array();
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Thanks!";
$body2 = "
TEXT TO EMAIL RECEIVER
\n\n"; foreach ($fields2 as $a => $b){ $body2 .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
// ERROR MESSAGES
if($from == '') {print "MISSING EMAIL ADDRESS.";}
else {
if($name == '') {print "MISSING NAME";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $body2, $headers2);
if($send)
{header( "Location: http://mysite/send.php" );}
else
{print "MISSING EMAIL ADDRESS ALL FILDS MUST BE FILLED!"; }
}
}
?>
Best if you use a dedicated script for sending emails. Such as PHPMailer which gives you various config options including SMTP:
// Send Mail
$mail = new PHPMailer(); // initiate
$mail->IsSMTP(); // use SMTP
// SMTP Configuration
$mail->SMTPAuth = true; // set SMTP
$mail->Host = "myhost"; // SMTP server
$mail->Username = "email#email.com";
$mail->Password = "password";
$mail->Port = 465; // change port is required
This is one way to do it. You need to include PHPMailer
#somewhere in code before you call function
include($path_to_PHPMailer."class.smtp.php");
function sendEmail($email,$name,$title,$content,$who=false,$att=array('')){
//VARIABLE $email is email of sender
//VARIABLE $name is name of sender
//VARIABLE $title is title of email
//VARIABLE $content is content of email
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
// DOUBLE $mail->Host = "your email_server"; // SMTP server
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "your email_server"; // sets the SMTP server
$mail->Port = server port; // set the SMTP port for the GMAIL server
$mail->Username = "your username"; // SMTP account username
$mail->Password = "your password"; // SMTP account password
if($who){
$mail->SetFrom($email, $name);
$mail->AddReplyTo($email,$name);
$address = "set your email";//EMAIL OF RECIPENT
} else{
$mail->SetFrom("set your email", "your name (or service name)");
$mail->AddReplyTo("set your email","your name (or service name)");
$address = $email;
}
$content=str_replace("\n", "<br>", $content);
$mail->Subject = $title;
$mail->MsgHTML($content);
$mail->AddAddress($address, $name);
$mail->CharSet='utf-8';
if($att[0]!=''){
foreach ($att as $at){
$mail->AddAttachment($at);
}
}
if(!$mail->Send()) {
return false; //$mail->ErrorInfo;
} else {
return true;
}
}