Not getting Confirmation Code on users email - javascript

I'm using Registration Form from the link below.
https://github.com/simfatic/RegistrationForm/tree/master/source
The only problem I'm facing is that I'm not getting the confirmation code/link on my(user) email ID.
On my other(admin) email ID, I'm getting the mail that a new user has registered. Even in my SQL, I'm receiving all the information like username, password and confirmation code. But it is not sending the confirmation code/link to the user.
Please Help.
Thank you

I just had a look through the code and it looks fine, you need to double check you corrected all the placeholders correctly, it might be you forgot to change one of them so now it can't push data to the users email.
I can't see what you changed the code to so unable to help you much more.

#AnonyMate
Emails can be sent when it's the live server.
BUT if you want to set email working facility in localhost, then you have to set SMTP configuration as below.
NOTE:- This is just basic setup for SMTP configuration. Different Email libraries may have different syntax.
$mailconfig['charset'] = 'utf-8';
$mailconfig['mailtype'] = 'html';
$mailconfig['newline'] = "\r\n";
if($_SERVER['HTTP_HOST']=="localhost")
{
//SMTP configuration
$mailconfig['protocol'] = 'smtp';
$mailconfig['smtp_host'] = 'ssl://smtp.gmail.com';
$mailconfig['smtp_port'] = 465;
$mailconfig['smtp_user'] = 'your Gmail Email-ID';
$mailconfig['smtp_pass'] = 'your Gmail Email-password';
}
So in your project, please refer source/include/class.phpmailer.php, change SMTP settings accordingly. Also find on which page there is an "email send" functionality. And set above variables values on that page as per that syntax.
EDIT:- Found the page on which there is an email send functionality.
/source/include/fg_membersite.php
In above file, in this function SendUserWelcomeEmail(&$user_rec)
Also in this file /source/include/class.phpmailer.php, make below changes.
NOTE :- Dont't delete old data. just comment it.
//var $Mailer = 'mail';
var $Mailer = 'smtp';
//var $Host = 'localhost';
var $Host = 'ssl://smtp.gmail.com';
//var $Port = 25;
var $Port = 465;
var $SMTPSecure = "ssl";
var $Username = 'your Gmail Email-ID';
var $Password = 'your Gmail Email-password';

Related

PHP Mailer returns PHP Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not authenticate

I saw many similar questions, like my, but never the one, which helps me. I am trying PHPMailer from https://github.com/PHPMailer/PHPMailer. I was testing it with xampp server and everything worked fine. But when I uploaded whole phpMailer on my page, some issues appeared. In my log file, I am still getting this error:
PHP Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not authenticate. in /web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php:2089
Stack trace:
#0 web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php(1900): PHPMailer\PHPMailer\PHPMailer->smtpConnect()
#1 web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php(1614): PHPMailer\PHPMailer\PHPMailer->smtpSend()
#2 web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php(1447): PHPMailer\PHPMailer\PHPMailer->postSend()
#3 web/test/idk.php(31): PHPMailer\PHPMailer\PHPMailer->send()
#4 {main}
thrown in web/test/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 2089`
Does anybody know, how to fix this? I am pretty sure my log in credentials are OK. The weird thing is that it is working on xampp fine, but not on my page. I am using the newest PHPMailer, and I didnt edited anything, so you can see the code on PHPMailer github.
If someone needs additinal information, just let me know.
Thank you so much!
EDIT: Here is my idk.php file (the code snippet didn't worked fine, but I think you can read it):
<?php
declare( strict_types = 1 );
// Check if the form is submitted
if ( isset( $_POST['submit'] ) ) {
// retrieve the form data by using the element's name attributes value as key
$subject = $_REQUEST['subject'];
$body = $_REQUEST['body'];
$sender = $_REQUEST['sender'];
require __DIR__ . '/vendor/autoload.php';
$mailer = new \PHPMailer\PHPMailer\PHPMailer( true );
//$mailer->SMTPDebug = \PHPMailer\PHPMailer\SMTP::DEBUG_SERVER tento řádek povoluje client -> server a server -> client zprávy
$mailer->isSMTP();
$mailer->Host = 'smtp.gmail.com';
$mailer->SMTPAuth = true;
$mailer->Username = 'my#mail.com';
$mailer->Password = 'myPassword';
$mailer->SMTPSecure = \PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
$mailer->Port = 587;
$mailer->setFrom( 'my#mail.com' );
$mailer->addReplyTo( 'my#mail.com' );
$mailer->addAddress( $sender );
$mailer->isHTML( true );
$mailer->Subject = $subject;
$mailer->Body = $body;
$mailer->send();
}
?>
Maybe I should say that I am using .htaccess file on my web hosting. I am not sure, but maybe this is the reason, why I am getting those errors. When I am trying to access the idk.php file, I am getting http error 500. I did some research and there is some connection beetween this 500 error and htaccess file.
EDIT:
I turned off less secure apps, but it still does not work. I changed port to 465 and now the error in on line 2076 in this file: https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php
This is gmail issue, you need Turn off "Less secure app access"
More info:
https://support.google.com/accounts/answer/6010255?hl=en#zippy=%2Cif-less-secure-app-access-is-on-for-your-account%2Cif-less-secure-app-access-is-off-for-your-account
Turn off "Less secure app access"
https://myaccount.google.com/lesssecureapps
Example (PHPMailer v6.2.0)
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
* This uses traditional id & password authentication - look at the gmail_xoauth.phps
* example to see how to use XOAUTH2.
* The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
*/
//Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require 'vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// SMTP::DEBUG_OFF = off (for production use)
// SMTP::DEBUG_CLIENT = client messages
// SMTP::DEBUG_SERVER = client and server messages
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption mechanism to use - STARTTLS or SMTPS
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = 'CHANGEME';
//Password to use for SMTP authentication
$mail->Password = 'CHANGEME';
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('CHANGEME', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML('This is a plain-text message body');
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//send the message, check for errors
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
//Section 2: IMAP
//Uncomment these to save your message in the 'Sent Mail' folder.
#if (save_mail($mail)) {
# echo "Message saved!";
#}
}
Taken from https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
I see you are using Google SMTP. Try enabling “less secure apps” in your Google account. Also make sure you have added your email address the “allowed senders” list.
As this was working on your local machine and not your server, you may also want to add your server IP to the allowed connections.
I’m not sure you need the leading backslash here:
$mailer = new \PHPMailer\PHPMailer\PHPMailer( true );
Or here:
$mailer->SMTPSecure = \PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;

Is there any way to mail merge with my own domain name instead Gmail

Here what I want to do is :
Send an email by mail merge by writing a script in App Script. (Success)
I have configured 2 domain email addresses in my Gmail along with my basic Gmail address.
I want to send an email via xyz#domainname.com instead of xyz#gmail.com, the Google Sheets owner.
here what I have done to send an email via Gmail
var first = 0;
var last = 1;
var email = 2;
var emailTemp = HtmlService.createTemplateFromFile("email");
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("NAJ");
var data = ws.getRange("A2:C" + ws.getLastRow()).getValues();
data.forEach(function(row){
emailTemp.fn = row[first];
emailTemp.ln = row[last];
var htmlMessage = emailTemp.evaluate().getContent();
GmailApp.sendEmail(row[email], "Important Test", "Your email does not support HTML.",
{name: "Email App", htmlBody: htmlMessage}
);
});
}
The only thing I need is to change the sending email address.
Any help would be highly appreciated. pardon my bad English
Explanation:
Your goal is to send emails from a specific email account regardless of the email account that is currently executing the script.
Approach 1:
One way to approach that is to use an installable trigger. As per the documentation:
Installable triggers always run under the account of the person who
created them. For example, if you create an installable open trigger,
it runs when your colleague opens the document (if your colleague has
edit access), but it runs as your account. This means that if you
create a trigger to send an email when a document is opened, the email
is always be sent from your account, not necessarily the account that
opened the document.
The idea here is to create an installable onEdit trigger from xyz#domainname.com so whenever the other emails edit a particular cell, the emails will be send.
The limitation of this approach is that we need to make sure that we trigger the code when we really want to and not every time a cell is edited. We can create a checkbox, and upon clicking on the checkbox (it does not matter which account did that) then the script will be executed and the emails will sent by the email account who created the installable trigger.
Approach 2:
Create email aliases. Here is the official documentation on how to do that and also this thread might be useful to create them programmatically. The restriction here is that to add an email alias, you must be a Google Workspace administrator.
Solutions:
Solution 1:
Create a checkbox in cell D1 of the sheet NAJ. The cell is up to you but you need to adjust the script accordingly.
Change the name of the function to add the event object. This will allow us to get edit info such as which cell is edited.
The new function will be:
function myInstallableOnEditFunction(e) {
const arng = e.range;
if(arng.getSheet().getName()=="NAJ" && arng.getA1Notation()=='D1' && arng.getValue()==true){
var first = 0;
var last = 1;
var email = 2;
var emailTemp = HtmlService.createTemplateFromFile("email");
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("NAJ");
var data = ws.getRange("A2:C" + ws.getLastRow()).getValues();
data.forEach(function(row){
emailTemp.fn = row[first];
emailTemp.ln = row[last];
var htmlMessage = emailTemp.evaluate().getContent();
GmailApp.sendEmail(row[email], "Important Test", "Your email does not support HTML.",
{name: "Email App", htmlBody: htmlMessage}
);
});
}
}
Finally, create an installable onEdit trigger function from the xyz#domainname.com account. You can do that either manually from the current project's trigger menu or programmatically.
After that, upon clicking on cell D1 by any account, the emails will be sent by xyz#domainname.com.
Solution 2:
After you have created email aliases (see Approach 2), you can use the getAliases() method, here is a sample script. I haven't tested on my own, but you can explore also this possibility.
// Log the aliases for this Gmail account and send an email as the first one.
var me = Session.getActiveUser().getEmail();
var aliases = GmailApp.getAliases();
Logger.log(aliases);
if (aliases.length > 0) {
GmailApp.sendEmail(me, 'From an alias', 'A message from an alias!', {'from': aliases[0]});
} else {
GmailApp.sendEmail(me, 'No aliases found', 'You have no aliases.');
}

How to send email using Javascript in a simplest way?

I'm doing the final project in my XML & JavaScript course and I'm having trouble with sending email via JavaScript.
I found this page: http://smtpjs.com/. But it requires SMTP credentials, I don't know what SMTP credentials is.
Who has used smtpjs.com or who has the solution please help me.
P/s: Do I need to upload my code to a host to send email. I always open html file from my computer, I wonder whether it will be able to send email or not.
First of all, I don't think you should run your code from the html file. You run it from a server to properly communicate with smtp.js
You can try this:
$('#form-submit').click(function () {
submitForm();
});
function submitForm() {
// Initiate Variables With Form Content
var name = $("#name").val();
var email = $("#email").val();
var message = $("#message").val();
if (name == "") {
alert('Invalid Name');
return;
}
if (message == "") {
alert('Message cannot be empty');
return;
}
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
if (!emailReg.test(email)) {
alert('Invalid Email');
return;
}
Email.send("from#email.com",
"to#email.com",
"Message from " + name + " " + email,
message,
{
token: "63cb3a19-2684-44fa-b76f-debf422d8b00",
callback: function done(message) { alert("sent") }
});
}
I also used smtpjs and sendgrid.
I hope this helps.
If you want to send an email in javascript, you should turn on allow secure app access in Gmail.
Google will not let you send emails if you do not turn on allow the less secure app in Gmail.
Here is the link to:
Turn On Allow Secure App Access
Please note if you turn on the function in google, it is easy for attackers to find information about your Gmail account.
It is recommended to create an account just for development.
SMTP is the server that handles mails. Here is google's: 'smtp.gmail.com'.
You can directly send an e-mail from javascript. I suggest you go for JSON.

Generate 30 second preview of mp3

i want to generate a 30 sec preview from the mp3 file using custom php script. the script will automatically trip the clip to 30 sec preview and after that the audio file will stop automatically.
moreover, i am not sure of any libraries on the system so please share step by step process with me.
It's no good idea but:
SELECT * FROM users where (email = 'mohsin#ac.com' OR username = 'mosin')
and password = 'sdssd'
I think you must authenticate only with username, you can decide to use email field as username.
$i_want_to_login_by_email = true;
$field = 'username';
if( $i_want_to_login_by_email )
{
$field = 'email';
}
$qry =<<<Rohit
SELECT * FROM users where {$field} = "{$value}" and password = 'sdssd'
Rohit;

Sending mail using CDO JavaScript error - Server is undefined

I got this code to send email using SMTP server, I tried many configuration of it that I found online, also VBscript similar code, and non of it is working.
I want to focus on this code, when I'm opening the HTA I'm getting error in line 8, says 'Server is undefined', What should I do to define it?
var cdoConfig = Server.CreateObject("CDO.Configuration");
cdoConfig.Fields("cdoSMTPServerName") = "194.90.9.22";
var cdoMessage = Server.CreateObject("CDO.Message");
cdoMessage.Configuration = cdoConfig;
var cdoBodyPart = cdoMessage.BodyPart;
cdoMessage.To = "aaa#gmail.com";
cdoMessage.From = "xxx#ddd.com";
cdoMessage.Subject = "CDO Test in JScript";
cdoMessage.TextBody = "This is a test email sent using JScript.";
cdoMessage.send();
Thanks,
Rotem
Jan, you should see that code uses "Server" (VBS), is it recommended ¿?
You may check this:
Your server(running the code) is not allowed to send (mail forwarding).
Auth, .Item(cdoSMTPAuthenticate) = cdoAnonymous, you should see if there's some auth on your mail server.
Hope this helps,
sorry for the delayed response looks like instead of using the server ip you need to spicify the server address for example smptout.secureserver.net but replace with your smpt address also most smtp server require username and password you will need to define these in your code.
in vbs it would be defined like so
Set emailConfig = emailObj.Configuration
emailConfig.Fields("smtpserver") = "your smtp address"
emailConfig.Fields("smtpserverport") = your smpt port
emailConfig.Fields("sendusing")= 2
emailConfig.Fields("smtpauthenticate") = 1
emailConfig.Fields("smtpusessl") = true/false "used for ssl"
emailConfig.Fields("sendusername") = "your smtp username"
emailConfig.Fields("sendpassword") = "your smtp password"
emailConfig.Fields.Update
i do not know js very well so i am unable to convert the vbs code to work in js. i hope this is some help

Categories