5

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); 
Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
  • 1
    define 'it does not work'. no errors? Are you sure https points to the same vhost settings as http? – tlenss Jul 20 '13 at 15:33
  • 2
    Just a tip, don't use `mail()`. It is triggered and sent to Junk folders by almost every provider. – Vlad Jul 20 '13 at 16:02
  • 1
    Try sending your mail using a 3rd party SMTP library like http://stackoverflow.com/questions/712392/send-email-using-gmail-smtp-server-from-php-page – Tom Jul 20 '13 at 16:26
  • @tlenss When I say it doesn't work, I mean that it runs successfully however I never receive the email. I can only receive the email if I use HTTP:// – johnny_pink Jul 20 '13 at 17:00
  • 4
    There's no link between the inbound protocol and the operation of the PHP mail() function. This is not the problem you're looking for. Move along now... – Dave S. Jul 20 '13 at 17:16
  • 1
    The link to the email script is this a relative link when you are on the email form on https. Or is it pointing to http rather then https:// not sure if this would make a difference though – Liam Sorsby Jul 20 '13 at 20:19
  • 1
    @Vlad `mail()` just sends mail. It's never its fault if the mail lands in the spam folder on the recipient. This is a complex issue of how your mail delivery is set up. `mail()` is simply a low level tool in the process. – deceze Jul 20 '13 at 20:20
  • @LiamSorsby I am using AJAX to request the email being sent. The request looks look like this: $.get("supportTicket.php?email="+ $('#support_email').val() + "&phone="+ $('#support_phone').val() + "&fname="+ $('#support_fname').val() + "&lname="+ $('#support_lname').val() + "&issue="+ $('#support_issue').val(), function(responseText) { }); – johnny_pink Jul 21 '13 at 13:14
  • @DaveS. So you do not think there is anything that would cause mail() to function differently on https protocol VS http protocol? Because that is literally the only thing I change causing it to work. I use AJAX for all the requests to the mail scripts so there are no hard coded http links. I just don't understand what would be causing this. – johnny_pink Jul 21 '13 at 13:20
  • Have you tried a simple mail function outside of Ajax to see if it works on http and https? – Liam Sorsby Jul 22 '13 at 06:27
  • So I got back to work today and can only receive emails with https protocol. On my phone, with 3G i can send with both http and https and at home I can only send with http. Thoughts on why this would occur? – johnny_pink Jul 22 '13 at 12:43

1 Answers1

0
$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 :)

Nev
  • 1,529
  • 21
  • 18
Tashen Jazbi
  • 1,068
  • 1
  • 16
  • 41
  • 1
    The only difference between this and what I was doing was putting my TO as a variable first. I have tried making this change and it makes no difference. Again, the email gets sent without issue when I am on the site with http://. I will receive the email everytime. All i do is switch to https:// and then I won't receive a thing. Makes no sense. – johnny_pink Jul 21 '13 at 13:07
  • check your spam or junk folders,your email would be there :) – Tashen Jazbi Jul 21 '13 at 14:15