• Resolved hittheroadjack

    (@hittheroadjack)


    So far, I’ve been workung with WP3.5.1 and decided now to update to WP3.9.2. Yet, I am facing problems with login/logout actions/hooks.. I am using the actions as recommended like so:

    add_action('wp_login', 'PN_on',10,1);
    
    function PN_on($user){
    	global $wpdb;
    	$GLOBALS['PM'] = $user;
    	$us = get_user_by('login', $user);
    	add_user_meta($us->ID,'login',$user );
    	wp_mail('mail@to.me', 'PM_signon', dbg_r($us->user_login));
    	if ( in_array('administrator',$us->roles ) ) {
    //		wp_mail('mail@to.me', 'PM_signon_Admin', dbg_r($us->user_login));
    		}
    }

    When I try to login, the process is not completed and -in debug mode- I get a message output like ‘cookies are de-activated due to unexpected output’ and further on the infamous ‘cannot complete header’-error and finally login hangs up.
    If I comment out the wp_mail lines, everything works perfect.
    It worked until WP3.5.1 but obviously no longer now.
    How can I send an email during login process on certain conditions in WP3.9.2?
    Should I use ob_start here instead?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    What exactly does the dbg_r function do?

    Thread Starter hittheroadjack

    (@hittheroadjack)

    It is just my replacement for print_r with my own formatting of the output

    Thread Starter hittheroadjack

    (@hittheroadjack)

    Actually, last night I found out that this might be a problem with the wp_mail itself.
    I tested all this with a migrated WP site with a different domain name on the same server. I am not able to send emails from a different domain name other than the original domain. It might be a config problem of sendmail for multiple domains.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    I am not able to send emails from a different domain name other than the original domain.

    Well, this is generally to be expected. A server can only send mail as itself, not as some arbitrary domain. Upstream servers will likely reject the mail and not send it if they don’t believe in the from line.

    The actual configuration of a mail system is outside the scope of WordPress. It simply uses the facilities provided by the server and the PHP install to send the mail, it doesn’t have the ability to send mail directly outside of the server’s configuration.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_login action and wp_mail’ is closed to new replies.