Jump to content

Recommended Posts

Posted

I am working on a registration script here. It used to work and send an email with a validation code to a new user.

But it has stopped working. Nothing gets sent. How can I troubleshoot this?

This is the bit that is supposed to send the email:

Spoiler

$fu->addHookAfter('FrontendUser::save', function($event) use($fu, $input) {
	if($event->return === true) {
		if(!empty($input->post->password) && !count($fu->form->getErrors())) {
			$subject = "Welcome - your new account at mydomain.com";
			$emailContentPlain = "Your connection details:\nUsername: {$fu->userObj->name}\nEmail: {$fu->userObj->email}\nPassword: {$input->post->password}";
			$mail = wireMail();
			$mail->to($fu->userObj->email);
			$mail->subject($subject);
			$mail->body($emailContentPlain);
			$mail->send();
		}
	}
});

 

I tried replacing wireMail() with mail(). That had no effect.

A php contact form in a Wordpress site on the same server/hosting account still works. It could still be something in the email setup on my server, but I have no idea where to start.

Is there a quick test to see if sending email from PW works?

Posted
6 hours ago, modifiedcontent said:

Is there a quick test to see if sending email from PW works?

You can activate (called "installing" in standard PW lingo, which is a bit confusing, since it comes with the system being already available) the core module called "Forgot Password", so that you can send a password reset emails form the admin login screen.

  • Like 1
Posted

First thing would be to check that those two "if" tests are being passed. You can do this by logging a message after each test. Or it's really easy with Tracy Debugger:

$fu->addHookAfter('FrontendUser::save', function($event) use($fu, $input) {
	if($event->return === true) {
		bd('test one passed');
		if(!empty($input->post->password) && !count($fu->form->getErrors())) {
			bd('test two passed');
			// the rest of your code
		}
	}
});

 

  • Like 1
Posted

Thank you for your responses tpr, szabesz and Robin S!

My problem was caused by unrelated server config issues, but I'll leave this thread here.

I am trying to understand the basics of sending from PW. The registration script sends from 'processwire@mywebdomain.com'.

Where is that sender address set in PW? It is not the admin's email address. Is there an email setup config somewhere in admin?

Posted
12 hours ago, modifiedcontent said:

Where is that sender address set in PW?

As far as I know, it is module configuration based, and there is no global address to work with, except if you implement such a thing. So you need to go to the module's setting and set it there.

about the API:

and https://processwire.com/api/ref/mail/

so you can create a custom admin setting page (eg. like this https://processwire-recipes.com/recipes/create-custom-admin-settings-page-link-in-admin-menu/) and also hook into send() and change the "from" address according to your setting:

https://processwire.com/api/ref/wire-mail/send/

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...