Jump to content

How to call Mailto


Nepherael

Recommended Posts

I'm trying to build a contact form to put in a block on my right column. I have all the HTML to build the form but I don't know how to call the mailto function. 

 

Prestashop already has a mailto.php file right? can anyone tell me how I would call that script in the coding of my form? I would prefer to use what prestashop already has instead of making a generic mailto script since I don't know how to protect it very well and may make mistakes in coding.

Link to comment
Share on other sites

I believe I have all the right stuff to call the mailto function but I'm not sure what it is. There is a file under

 

tools/smarty/plugins/function.mailto.php 

 

but I'm not sure if it's what I'm looking for. Is there a different mailto function?

 

EDIT: I'm also looking at tools/mail.php but I am having a hard time with naming the variables. any help greatly appreciated

 

EDIT2: using both of the mail functions I've mentioned sends me to an unknown url each time. I just get a prestashop page saying that the page doesn't exist. I don't have a confirmation page set to load in my code so I don't know why it is doing that

Edited by Nepherael (see edit history)
Link to comment
Share on other sites

Okay I've made it a little further along. I'm not good at coding and have never learned HTML in the traditional sense so some things that are simple end up being very hard for me

 

Everything seems to function but when the form calls the mail.php function it takes me to mydomain.com/mail.php 

 

I don't know how to make it mail me the form contents instead of directing to that URL. Maybe I'm just using the wrong code to call the mail.php function?

 

Here is my code:

 

<form action="mail.php" method="post">
<table style="width: 400px;" border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td class="bodytext" width="29%">Your name:</td>
<td width="71%"><input id="from_name" type="text" name="name" size="32" /></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input id="from" type="text" name="email" size="32" /></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea id="message" class="bodytext" name="comment" rows="6" cols="45"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send" /></td>
</tr>
</tbody>
</table>
</form>
 
It's very basic but it is for testing purposes
Link to comment
Share on other sites

this is a bit wrong idea in my opinion, if you want to use form like this one you should - in my opinion - create mailing method for example in Frontcontroller, then you will not have to call mail.php file

Thank you Vekia. I will see what I can do. Can you elaborate a bit on how to make a front controller mail function if you know?

Link to comment
Share on other sites

open file: classes/controller/FrontController.php

 

there is a function:

	public function init()
	{

inside this function create code:

if (isset($_POST['mysendmailbutton'])){
// mail code here
}

and in front office create form with submit button named mysendmailbutton

Link to comment
Share on other sites

oh yes i understood you. I'm working on it now.

 

I mean the actual contact form to fill out. in the form code there's always an action and a method and I'm asking if I use a different action or if I can leave the action out.

 

Sorry I'm just going along with form examples that I've adapted

Link to comment
Share on other sites

still having some trouble but I think I'm close. Pretty sure I just have a small error in the code somewhere. Can anyone take a look and see where my mistake is?

public function init()
	{
        if (isset($_POST['sitefeedbackbutton'])){
        $to = '[email protected]';
        $subject = 'Message from PPS feedback form';
        
        $message = 'From: '.$name."\n";
        $message .= 'E-mail: '.$email."\n";
        $message .= 'Message: '.$comment;
        
        mail($to, $subject, $message);
        }

That is the code located in classes/controller/frontcontroller.php

 

and here is the form code

<form method="post">
<table style="width: 400px;" border="0" cellspacing="2" cellpadding="0">
<tbody>
<tr>
<td class="bodytext" width="29%">Your name:</td>
<td width="71%"><input id="name" type="text" name="name" size="32" /></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input id="email" type="text" name="email" size="32" /></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea id="comment" class="bodytext" name="comment" rows="6" cols="45"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="sitefeedbackbutton" value="Send" /></td>
</tr>
</tbody>
</table>
</form>
Edited by Nepherael (see edit history)
Link to comment
Share on other sites

I'm not receiving any errors and the email is not sending. When I click the send button the page reloads with no email sent. I also tried commenting out the code in frontcontroller.php and when I submit the form that way still same result (the page reloads). So I am thinking maybe the form is not communicating with the front controller file?

 

Also, just to add some information I am using the content box module for prestashop. It allows me to place a block anywhere with custom code in it so i don't have to modify prestashop files. I don't know that it makes a difference

Link to comment
Share on other sites

to the if (isset($_POST['sitefeedbackbutton'])) condition add something to verify this condition: print_r("FORM SUBMITED");

if (isset($_POST['sitefeedbackbutton'])){
print_r("FORM SUBMITED");
...
...
}

then try to send form once again, if you will see the "FORUM SUBMITED" message - it mean, that code works but you've got some issues with mail function

Link to comment
Share on other sites

Ok I just tested it. There was no "form submitted" message. The page reloaded and my form was still there. It changed shape though, it got slightly larger after submitting it with the print_r line which was weird.

 

Thank you for taking your time to help me track this down. At this point I am totally lost. I'm sure it will just be a small code change that fixes it though

 

Edit: The code seems to be fine. Maybe this module ContentBox can't communicate with frontcontroller.php?

Edited by Nepherael (see edit history)
Link to comment
Share on other sites

i checked your code on my demo page based on latest ps and it works well. I added to if condition simple code : print_r($_POST);  and this is what i've got:

rmGLMSc.png

 

it mean that it works well. Inspect form code from your page source, maybe it looks different than example that you pasted above (sometimes contentbox changing the code)

Link to comment
Share on other sites

I added the print_r($_POST); and it is returning the data array so it is working with frontcontroller.php

 

The problem seems to be with my mail code. 

 

 

 

EDIT: 

 

Ok I added and if/else clause to let me know if the mail() function was completed and it is showing as successful but the mail is not leaving the server.

 

Really not sure where to go from here. Here's my current mail code. Must be some other issue

public function init()
	{
        //Custom code for feedback form
        
        if (isset($_POST['sitefeedbackbutton'])){
            
        print_r($_POST);
        $to = '[email protected]';
        $subject = 'Message from PPS feedback form';
        
        $message = 'From: '.$name."\n";
        $message .= 'E-mail: '.$email."\n";
        $message .= 'Message: '.$comment;
        
        $headers = "From: $name\r\n";
        $headers .= "Reply-To: $email\r\n";

        $sent = mail($to, $subject, $message, $headers);
                
        if ($sent)
        {
        echo 'Success';
        }
        else
        {
        echo ('failed');
        }
        }

Might be being blocked as spam or something like that. I'm guessing that's out of the scope of the prestashop forums. I will do my best to search

Edited by Nepherael (see edit history)
Link to comment
Share on other sites

yeah, I tested another form in contentbox and created a mail.php file in my themes/default folder.

 

<form action = ".../themes/default/mail.php method = "POST">

 

EDIT: This form did work!

 

I just tested it and it did send the email. I compared the code to what we added to frontcontroller.php and I can't find any differences. 

 

As of right now this issue is solved but I will do some testing and see if I can get the frontcontroller.php mail form working

Edited by Nepherael (see edit history)
Link to comment
Share on other sites

what you've got before this line?

 

before that line was just <? php 

 

but the problem was "[email protected]" should have been '[email protected]'. it worked once I changed that.

 

I double checked all the code in frontcontroller and it matches the mail.php file that is confirmed to work but still no mail received when using frontcontroller.

 

weird

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...