-1
  1. I have a form created on my index.html - modal that pops up when clicked.
  2. Form is simple NAME: EMAIL: MESSAGE - SEND
  3. It is for a subscription that needs to be 'mailed' to me (with name/email/message body)
  4. Presently on HostGator. They do not use smtp - must be php. I know zero about php. I don't have time to sit and study it just for this one element on the webpage. (future goals maybe)

I am working with tutorials for this project. The following script was before I learned I could not use smtp. I do not want to create index.php etc, files. I would prefer to remain html with just the send portion of php. Kindness appreciated.

<script src="https://smtpjs.com/v3/smtp.js">
</script>
  <script>
      function sendEmail(){
        Email.send(
          {
            Host : "smtp.gmail.com",
            Username : "testing@gmail.com",
            Password : "XXDDDSSS",
            To : 'main-account@gmail.com',
            From : document.getElementById("email").value,
            Subject : "New Connection",
            Body : "Name: " + document.getElementById("name").value + "<br> Email: " + document.getElementById("email").value + "<br> Message: " + document.getElementById("message").value 
        }).then(
          message => alert("Message sent successfully")
      );
      }
  </script>
  • Sorry this is not a free write-my-code service. See also [ask] and the [tour]. We don't replace your basic learning and effort. You can hire a freelancer if you want someone else to do all the work. This site is for programmers to _help_ each other with specific issues / bugs which might also be of benefit to the wider community, not to provide free labour for those who don't want to learn it themselves. – ADyson Sep 28 '22 at 17:43
  • P.s. I'm not sure the issue is lack of support for SMTP, it's much more likely to be simply that you can't send emails from client-side javascript - that has nothing to do with your host because it tries to happen in your browser. You can send emails from server side code such as php, either using the built in mail function, or via smtp using a library such as phpmailer. – ADyson Sep 28 '22 at 17:45
  • BTW there are lots of php contact form tutorials you can learn from already online, if you want a free resource. – ADyson Sep 28 '22 at 17:46
  • @ADyson I read this site is to share problems and help one another, those who are learning (as I am) and those who are experienced on various levels. I am not looking for someone to write code for me. I'd have specified that. I just asked for help. And HostGator doesn't allow/support SMTP. Only can mail in PhP. Thanks for your guidance. – KittyMichele Sep 29 '22 at 02:46
  • `I am not looking for someone to write code for me`...then what exactly _are_ you looking for? Because this is a site where people talk about problems in their code and then the answers show corrections to that code, to fix a specific bug. But you didn't really ask a question, anyway. Also, `HostGator doesn't allow/support SMTP`...what's your evidence for this please? I don't see anything about it online. – ADyson Sep 29 '22 at 09:35
  • I spoke to technical support. I didn't see anything about it when I bought my contract, either. And really, why would I lie, get myself all twisted up over your response, or just allow myself to be a target for you. I asked questions. So to make the question perhaps clearer, do I have to make my entire site dot.php, or can it stay HTML (reminder: I would prefer to remain HTML with just the send portion of PHP. Kindness appreciated) and create the action of sending to my email with some sort of mailer.php? thank you again. – KittyMichele Sep 29 '22 at 21:38
  • I didn't suggest you were lying (you're right - what would be the point of that?), just that it's possible you're mistaken, or misunderstood what they told you (or perhaps they even misunderstood what you asked them and therefore gave the wrong answer...tech support teams do that all the time, especially the 1st line people). It's just that I see examples on the net of people using PHPMailer to send email via SMTP from hostgator. – ADyson Sep 29 '22 at 21:38
  • `do I have to make my entire site dot.php, or can it stay HTML`...it can stay as .html if you want, but you then need to use an AJAX request to send the email data to a PHP script which can then generate and send the email. Arguably this complicates matters (compared to just submitting a form via a standard postback), unless you're already comfortable with Javascript and AJAX. – ADyson Sep 29 '22 at 21:40
  • Also, just to make this one script work (without AJAX) you'd only need to convert this one script to .php. Your other pages can stay as they are, if they don't require PHP code to be executed within them. – ADyson Sep 29 '22 at 21:46
  • @ADyson Thank you. I spent about 20 minutes verifying, because I wasn't pleased with learning that they didn't permit the smtp anymore for safety reasons. I have zero knowledge of PHP. That's my problem. And I could be mistaken, but I believe I read in HGs docs that they cautioned against PHP sites. Something about creating a load... I really don't recall exact terminology. And thank you again, I'm more comfortable in HTML/CSS. I'm learning javascript et al. Just not prepared to add PHP to the mix. Maybe down the road. Thanks. – KittyMichele Sep 29 '22 at 21:58
  • I've been reading stack for a few years, following along but never joined. Same with a few other similar sites. Learn a lot, get confused a lot. Life goes on. – KittyMichele Sep 29 '22 at 21:59
  • well, you'll still need to add some PHP (or another server-side language supported by your host) if you want to get the email part working. But you can get ready-made scripts which can generate an email based on some submitted POST data, they're not hard to search for online...then just plug your AJAX request into that. – ADyson Sep 29 '22 at 21:59
  • `they didn't permit the smtp anymore for safety reasons`...when exactly did they introduce this restriction then? Because (for example) [here is a post from May this year, only a few months ago](https://learn.microsoft.com/en-us/answers/questions/840104/emails-from-phpmailer-script-on-hostgator-server-a.html) showing someone sending email from a hostgator server using PHPMailer and SMTP. (N.B. They are having a problem because sometimes the mail ends up in the recipient's junk folder, but they are certainly not being blocked from sending the mail in the first place.) – ADyson Sep 29 '22 at 22:04

1 Answers1

0
$.post('./send_email.php', {email_addr:'some email address', message:'some message'}, function(data) {});

The post will get you to your php code. My example only shows two of your values to be passed, but it gives you how to pass the values in a POST command.

Also, depending on what directory your post is occurring in, you will need to adjust the file directory path in my example.

I have not included any code to handle a return status from you php code.

This previous post may help as well Pure JavaScript Send POST Data Without a Form

Tim
  • 273
  • 2
  • 10
  • Thank you. I've spent hours on YT, Github, stacks etc google about keeping the site HTML w/only the modal submit button as the php send. I've found plenty saying I can mix html + php, but requires name.php. I appreciate this example and will play with it in the morning. I apologize for frustrating anyone. I spend an average of 6 hours upwards of 10 hours combing, studying and learning on various sites like Odin project, free code camp and Frontend mentor. Truly I'm all over the place. Wouldn't have tried seeking some guidance here if it weren't for the unexpected php issue. Thanks again. – KittyMichele Sep 29 '22 at 02:56
  • Please vote up my answer is this helps, as it helps me when you do. – Tim Sep 29 '22 at 16:51