mail() on https - https

I setup a website that uses PHP mail(). I can get it to successfully run if I hit the script on http:// but if I switch to https:// it does not work! I use Godaddy for hosting and have a certificate purchased through them. I am not sure if I need to setup anything in the php.ini file or not. My mailscript looks like this:
$from_respondent_email = "calendar#mydomain.com" ;
$headers_respondent_email = "From: $from_respondent_email";
$subject_respondent_email = "Technical Support Request";
$body_respondent_email = "We received a support ticket from mydomain.com:\n\n";
$body_respondent_email .= "Test block of text";
$send = mail("myname#gmail.com", $subject_respondent_email, $body_respondent_email, $headers_respondent_email);

$to ="myname#gmail.com";
$subject = "Technical Support Request";
$message = "We received a support ticket from mydomain.com:\n\n";
$from = "calendar#mydomain.com";
$headers = "From: $from_respondent_email";
mail($to,$subject,$message,$headers);
Try this. It'll work. I used this in my website and its working :)

Related

Google recaptcha when posting to different server

I have a form with recaptcha V2:
https://www.fisherwallace.com/pages/do-you-qualify-to-use-the-device
It posts to a different server and then redirects back to a different page on the server with the recaptcha form.
Recaptcha site says: "We detected that your site is not verifying reCAPTCHA solutions." I assume it's due to posting to the different server.
NOTE: You'll see I have a clumsy workaround at the moment to address the fact that the recaptcha does not challenge automatically. Without the workaround, the recaptcha is there but nothing happens on submit.
I found some sample PHP code for the server side...
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}
if(isset($_POST['comment'])){
$comment=$_POST['comment'];
}
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "Put your secret key here";
$ip = $_SERVER['REMOTE_ADDR'];
// post request to server
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) . '&response=' . urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response,true);
// should return JSON with success as true
if($responseKeys["success"]) {
echo '<h2>Thanks for posting comment</h2>';
} else {
echo '<h2>You are spammer ! Get the #$%K out</h2>';
}
Clearly lots of this code is moot since the user does not actually load the POST server page.
But will this part get the callback recaptcha needs?
$secretKey = "Put your secret key here";
$ip = $_SERVER['REMOTE_ADDR'];
// post request to server
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) . '&response=' . urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response,true);
// should return JSON with success as true
If the IP is a mismatch, can i hard code it using the IP from the originating server?
IP is optional
You need to do file_get_contents 'method' => 'POST' for siteverify

Use simple Php mail function in laravel instead of SMTP in Hostgator

I want to use simple php mail function in laravel (using hostgator hosting) instead of smtp what
changes should i do in mail.php and .env to achieve it in
Hostgator
.env file
MAIL_DRIVER=mail
MAIL_HOST=mail.mydomail.com
MAIL_PORT=587
MAIL_USERNAME=my email address
MAIL_PASSWORD=email password
MAIL_ENCRYPTION=none //as SSL is disabled
I want to implement php mail function in laravel but due to some reason its not working although when i run simple php script i.e
SIMPLE PHP SCRIPT that i tested with hostgator it is sending mail I just want to implement the same using laravel
Below is my index.php
$to = "mailhostingserver#gmail.com";
$subject = "This is subject";
$message = "This is simple text message.";
$header = "From:support#domain.in \r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo "Message sent successfully...";
}
else { echo "Message could not be sent..."; } ?>
I just want to implement the above index.php code in laravel

why is codeigniter email not functional for abc#company.com.np

I am using codeigniter email. Everything is correct except that mail isn't sent to my client email which is something like abc#companyname.com.np but goes to gmail and my office mail.I have bulk email ids to send to. Have I done something wrong or is it the problem of client's company mail settings ??
$this->load->library('email');
$config['mailtype'] = 'html';
$config['validate'] = TRUE;
$this->email->initialize($config);
$this->email->from('abc#gmail.com', 'ABCTechnologies');
$list = array($form->admin_email);
$this->email->to($list);
$this->email->subject($form->form_title);
$message = 'You have got a new Feedback. Here are the Details : <br/>';
'.$email_fields['message'].'<br/>';
$this->email->message($message);
$this->email->send();
where $list is array of mail id.Any suggesstions are welcome.
I changed the smtp also but to no avail.
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'mail.sipradi.com.np';
and smtp port is by default 25.
Help

Could not instantiate mail function in joomla 2.5.4

I am trying to send mail from my component when the user registers. I tried all three i.e PHPMail, Sendmail and SMTP but none works. I am testing it in localhost (WampServer 2.2) and the Joomla version is 2.5.4. I am not sure this is WampServer problem or Joomla or my own code. This is my code:
function postmail($name, $receiver){
jimport('joomla.mail.helper');
$mailer =& JFactory::getMailer();
$config =& JFactory::getConfig();
$sender = array($config->getValue( 'config.mailfrom'),$config->getValue( 'config.fromname' ) );
$mailer->setSender($sender);
$recipient = $receiver;
$mailer->addRecipient($recipient);
$body = "<body><br><p>";
$body .= "<strong>$name,</strong> ";
$body .= "</p><br></body>";
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$send =& $mailer->Send();
if ( $send != true ) {
//echo 'Error sending email: ' . $send->message;
return false;
} else {
//echo 'Mail sent';
return true;
}
}
It gets the error 'could not instantiate mail function'.
i am sure there are many reasons causing this problem. but to test you can always create a mail server of your own by installing this tool here http://www.toolheap.com/test-mail-server-tool/
you don't have to change anything except that you put localhost as the smtp host in joomla mail settings and then in your webserver's php.ini, add the smtp=localhost. thats it, it should work.
this is just to test whether your code is correct and you are using the correct mail settings in joomla. if this doesn't work then, i am sure the problem is not in your code but in your mail settings.
To understand what the problem is you really need to get the error message.
Change
//echo 'Error sending email: ' . $send->message;
to
echo 'Error sending email:'.$send->get('message');
then run it again. The error that you get should tell us why it isn't instantiating. Let us know what it says so we can help you out.

SMTP Codeigniter email error '354 End data with .'

I'm having trouble getting the Codeigniter email library working on a new server.
This code has previously worked before but has recently stopped working and I cannot for the life of me figure out why. Essentially, here is the code:
$this->email->from('example#example.com', 'Intranet');
$this->email->to($c['email']);//This is def a valid email
//$name is being obtained from elsewhere
$this->email->subject('Time manager reminder');
$this->email->message("
{$name[0]},
<br/><br/>You haven’t completed your time for today. Please don’t forget to do so<br/><br/>
Intranet
");
$this->email->send();
And the email.php config password
$config['mailtype'] = "html";
$config['priority'] = 1;
$config['protocol'] = "smtp";
$config['smtp_host'] = "my server..";
$config['smtp_user'] = "u/n";
$config['smtp_pass'] = "p/w";
$config['smtp_timeout'] = 1;
$config['validate'] = true;
The error I receive from $this->email->print_debugger(); is as follows:
data: 354 End data with .
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
You can view the full error on pastebin here http://pastebin.com/y9UeaEGY
I've crossed out the emails in all places, but I can assure you they are valid and used email addresses.
I'd appreciate any help you can offer. Thanks
I figured out the reason. Apparently, in the config, you need to set
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
manually in the email.php file. Codeigniter doesn't seem to do it by default. Odd :)

Resources