Jump to content

alexpi

Members
  • Posts

    28
  • Joined

  • Last visited

Posts posted by alexpi

  1. 5 minutes ago, LostKobrakai said:
    
    $m = $mail->new();
    $m->from('noreply@yourdomain.com');
    $m->to('alexpi@yourdomain.com');
    $m->header('Reply-To', $emailBackTo);
    $m->send();

    Like I said in the WireMailSMTP modules topic: If you use such a service do not send emails with a "From" address, which is not your own. 

    Thanks LostKobrakai, It makes sense now, and it works as expected!

  2. I used the WireMailSMPT module, signed up to an SMTP service (Mailjet), got SPF and DKIM authentications but the service prompts me to validate every email I receive!

    I am not sure if I am using $mail correctly, the docs are a little sparse. Do I need to add additional headers or something else?

     

  3. 2 hours ago, alan said:

    In case using Google for SMTP is the problem (perhaps Google is or may one day, restrict use?), a new account with Postmark gives you 25,000 'credits', but more importantly they are great for transactional emails.

    Ok, I signed up for a similar service. It works now, but I have a concern: Since my site's contact form receives emails from various people (the WireMail->from() value is different every time), I am asked to validate every single one before it passes. Is this the way these services work?

     

  4. Hello all,

    I am trying to setup WireMailSMTP with the Gmail SMTP server, trying everything I read in this topic with no success.

    The error I get that seems to say something (but I don't know what!) is =>  WireMailSmtpConfig: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt0

    The settings I am using are: (I think I entered every combination possible!)

    local hostname: the site's domain (is this wrong? I don't know if it's relevant but this domain is an addon domain)

    SMTP hostname: smtp.gmail.com

    SMTP port: 587

    use START_TLS

    SMTP user: my email from Google

    SMTP password: my above email password

     

    Am I doing something wrong?

  5. Hello,

    I have a Processwire site that was made some years ago, and I got a complaint that the emails originating from it, ended up in Gmail's spam folder. I updated Processwire to 2.8, and changed the PHP mail() function I used before, to the newer $mail helper. In the beginning I used a Gmail email for the recipient, but later changed to an info@site.com type, thinking that this could be the problem. Still, the emails are marked as spam.

    I used the following code (simplified):
     

    $name = $input->post['name'];
    $emailFrom = $input->post['email'];
    $message = $input->post['message'];
    
    $form = array(
        'name' => $sanitizer->text($name),
        'email' => $sanitizer->email($emailFrom),
        'message' => $sanitizer->textarea($message),
    );
    
    $message = "Name: $form[name]\n" . 
             "Email: $form[email]\n" . 
             "Message: $form[message]";
                     
    $email = $mail->new();
    $email->subject("Subject")
        ->to($pages->get('/settings/')->main_email)
        ->from($form['email'])
        ->body($message);
    
    $email->send();

    Should I use email header parameters? I can't find what to do in the docs.

    Thanks

  6. Is it possible to have page names with non-latin characters? I tried renaming a page to contain Greek characters in PWs admin, but It wasn't allowed.

    In my particular case all I needed was the page title, not a url, so I used a random number to store page names.

    $name = $wire->input->post['guest_name'];
    $message = $wire->input->post['guest_message'];
    
    $p->name = rand();
    $p->title = $wire->sanitizer->text($name);
    $p->body = $wire->sanitizer->textarea($message);

    I am not sure if this code is good, but it works.

  7. Hello,

    I developed a guestbook for a hotel site, that creates a page with a name and a small message for each person who writes.

    I used the following code which I found in these forums, and it works but only if the page name is written in English.

    $name = $wire->input->post['guest_name'];
    $message = $wire->input->post['guest_message'];
    
    $p = new Page(); // create new page object
    $p->template = 'testimonial'; // set template
    $p->parent =  wire('pages')->get('/guestbook/'); // set the parent 
    
    $p->name = $wire->sanitizer->text($name); // give it a name used in the url for the page
    $p->body = $wire->sanitizer->textarea($message);
    
    $p->status = Page::statusUnpublished;
    $p->save();

    If a guest writes a name in Greek for example, I get the following error:

    Fatal error: Uncaught exception 'WireException' with message 'Can't save page 0: /guestbook//: It has an empty 'name' field' in (etc)

    The strange thing is that the textarea part can be in any language. Isn't $sanitizer->text() safe for any character sets?

  8. Although bootstrapping PW on a file outside PW's directories and calling it with AJAX worked, I am not able to get multi-language field values from it.

    So, I am trying to include the contact validation code in a PW template as suggested here: https://processwire.com/talk/topic/4665-accessing-pagetitlelanguage-when-bootstrapped/

    The problem is that I can't find how to do that! The following is the code I am using, which works, but is not fetching the various validation messages.

    <?php
    
    	$emailTo = 'an email';
    	
    	$name = $input->post['name'];
    	$email = $input->post['email'];
    	$message = $input->post['message'];
    	
    	$form = array(
    		'name' => $sanitizer->name($name),
    		'email' => $sanitizer->email($email),
    		'message' => $sanitizer->textarea($message)
    	);
    	
    	$email = "Full name: $form[name]\n" . 
    	         "Email: $form[email]\n" . 
    	         "Message: $form[message]";
    	
    	$errors = array();
    	$data = array();
    	
    	if (empty($form['name']))
    		$errors['name'] = $out = __('Name is required');
    	
    	if (empty($form['email']))
    		$errors['email'] = $out = __('Email is required.');
    	
    	if (empty($form['message']))
    		$errors['message'] = $out = __('Message is required.');
    	
    	if ( ! empty($errors)) {
    	
    		$data['success'] = false;
    		$data['errors']  = $errors;
    	} else {
    	
    		mail($emailTo, "Thassos homes - Επικοινωνία", $email, "From: $form[email]");
    		
    		$data['success'] = true;
    		$data['success_message'] = $out = __('Your message has been send! We will reply to you soon.');
    	}
    	
    	json_encode($data);
    
    ?>
    
    <form action='./' method='post'>
        <div>
            <input type="text" id="name" name="name" placeholder="name"  />
            <input type="email" id="email" name="email" placeholder="email" required />
            <input type="submit" name="submit" value="send" />
        </div>
        <textarea id="message" name="message" placeholder="your message" required ></textarea>
     
        <div class="contact_message"></div>
        <div class="loading hidden"></div>
    </form>
    
    <script>window.jQuery || document.write('<script src="<?php echo $root_dir ?>js/jquery-1.11.0.min.js"><\/script>')</script>
    <script>
    	$(document).ready(function() {
    		var contact_message = $('.contact_message');
    		contact_form.submit(function(event) {
    		
    		contact_message.innerHTML = "";
    	
    		var contactData = {
    			'name' 		: $('input[name=name]').val(),
    			'email' 	: $('input[name=email]').val(),
    			'message' 	: $('textarea[name=message]').val()
    		};
    	
    		$.ajax({
    			type 		: 'POST',
    			url		    : '<?php echo $page->url ?>',
    			data 		: contactData,
    			dataType 	: 'json'
    		})
    			.done(function(data) {
    	
    				console.log(data); 
    	
    				if ( ! data.success) {
    				
    					if (data.errors.name) {
    						contact_message.text(data.errors.name);
    					}
    		
    					if (data.errors.email) {
    						contact_message.text(data.errors.email);
    					}
    		
    					if (data.errors.message) {
    						contact_message.text(data.errors.message);
    					}
    		
    				} else {
    					
    					$('.contact_form div, .contact_form textarea, .loading').addClass('hidden');
    					$(contact_form).append('<div class="success">' + data.success_message + '</div>');
    					
    					setTimeout(function(){
    						contact_form.toggleClass('hidden visible');
    					}, 3000);
    		
    					// window.location = 'index.php'; // redirect a user to another page
    		
    				}
    			})
    			
    			.fail(function(data) {
    	
    				// show any errors
    				// remove for production
    				console.log(data);
    			});
    	
    		event.preventDefault();
    	});
    })
    	
    </script>
    
    
  9. Sorry, this must have been vague!

    I have a contact.php file with PW bootstrapped, called via AJAX that contains the following code:

    include('../index.php');
    
    $contact = $wire->pages->get('/settings/contact/');
    $contact->of(true);
    $language = $wire->user->language;
    
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    $emailTo = 'an email';
    
    $name = $wire->input->post['name'];
    $email = $wire->input->post['email'];
    $message = $wire->input->post['message'];
    
    $form = array(
    	'name' => $wire->sanitizer->name($name),
    	'email' => $wire->sanitizer->email($email),
    	'message' => $wire->sanitizer->textarea($message)
    );
    // below is some form validation code that is irrelevant

    The form code is:

    <form action='<?php echo $root->url ?>includes/contact.php' method='post'>
       <div>
            <input type="text" id="name" name="name" placeholder="name" required />
            <input type="email" id="email" name="email" placeholder="email" required />
            <input type="submit" name="submit" value="send" />
       </div>
          <textarea id="message" name="message" placeholder="your message" required ></textarea>
                     
        <div class="contact_message"></div>
        <div class="loading hidden"></div>
    </form>  
    

    If I enter information in the form in English, the form works as expected. If I type in Greek, the form submission does not occur.

    If I remove the sanitizer functions, the Greek data pass and the form works again.

  10. I have a repeater with mp3s, and I am using the following code to get the path to the mp3.

    foreach ($settings->music as $song) {
       echo "<audio src='$song->url'></audio>";
    }

    but the path returned looks like this:

     /processwire/repeaters/for-field-157/for-page-1355/1396614455-2945-1/

    I am not getting the file ending in .mp3

    What am I doing wrong?

  11. Hello

    I have the following code:

    $houses = $pages->get('/houses/')->children('limit=6');
    
    foreach ($houses as $house) {
      echo "<li>";
      foreach ($house->repeater as $repeater_item) {
        echo $repeater_item->repeater_field;
      }
      echo "$house->title";
      echo "<a href='{$house->url}'>";
      echo "<h2>{$house->title}</h2>";
      echo "<img src='{$house->house_thumbnail->url}' />";
      echo "</a>";
      echo "</li>";
    }

    The problem is that I can't output the nested foreach(). I get a 'Invalid argument supplied for foreach()' error.

    Do I have a syntax error?

  12. Yes, the js is on a .php file. If I put a relative link I get a 403 Forbidden error. I can put the form processing .php file outside PW's directories, but it would be nice to use a PW template. In it, I wanted to have the various validation messages as user editable fields (for multilingual use reasons). So, if I understand correctly, it is not possible to have a PW template (that contains only php) to be called by an ajax request.

    Also, thank you all for your time, I am a web designer and my php knowledge is limited, so my questions/explanations may not be very clear!

  13. The url in the JS looks correct but does nothing. I tried the same thing with a validation.php file outside PW's folders and it works.

    When using:

    <form action='<?php echo $process->url ?>' method='post' id="contact_form">

    the proccesing happens in the $process page (with a redirect),

    but combined with:

    $.ajax({
    type  : 'POST',
    url  : '<?php echo $pages->get("/process/")->url ?>', // the url where we want to POST
    data  : formData,
    dataType  : 'json'
    });

    nothing happens.

  14. Hello all,

    I am having trouble with the following:

    I have created a template with contact form validation code (./site/templates/contact.php). I am using the action attribute of my form to point to this template, and the validation works, redirecting to this contact template which shows the relevant messages.

    Since I am displaying the contact form in a modal kind of thing, I want the validation messages to appear inside this modal without the page refresh and redirection. I am not very familiar with ajax, and I can't achieve showing the contents of contact.php inside this modal.

    I am trying to do something like this:

    $('#contact_form').submit(function(e) {
    $.ajax({
     type: "POST",
     url: "<?php echo $pages->get('/contact/')->url ?>",
     });
    e.preventDefault();
    })

    but this doesn't work.

    Any ideas?

×
×
  • Create New...