Ok i have a couple email functions, the one that works, sends an email to the recipiant and the one that doesnt work how i want it sends an email with an activation link in it.

the working email says its from support@domain.com (like i want it to say)

but the broken one says its from domain@host299.hostmonster.com (not what i want)

but the functions are nearly identicle... what is the problem. what do you suggest i do to fix it? am i not seeing something that im doing wrong?

im going to cry foreal lol

thanks for the help guys


Just look for the email functions and ull see where im talking about.


this doesnt work like i want it to

function sendVerificationEmail($email, $code){
		$to = $email;
        $subject = "Please activate your account at ".SITE_NAME;
        $from = "registration@domain.com";
        
        $headers = "From: $from\n".
						   "Reply-To: support@domain.com\n".
						   "X-Mailer: PHP/".phpversion();
				
       
        $message = "Welcome to domain.com\n" .
            "We see that you recently opened an account with us.\n" .
            "Before you can start using our services you need to activate your account.\n" .
            "Follow the link below to activate your account.\n" . 
			SITE_URL."user/activate/?e=" . $to . "&c=" . $code . "&action=activate\n\n" .
            "_______________________\n\n" . "This is an automated response from ". SITE_NAME .
            "\n\n" . "Please do not respond to this email.";

        $send = mail($to, $subject, $message, $headers);
        if($send){
        	return true;
        }else{
        	return false;
        }
	}

this does work how i want it to... and its not differant

function sendEmail($to, $from, $subject, $message){
		if(empty($to) OR !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i', $to)){
			$this->m->addMessage("email-form", "error", "The recipients email must be in the form of email@domain.com.");		
		}
		if(empty($from) OR !preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i', $from)){
			$this->m->addMessage("email-form", "error", "Your email must be the form of email@domain.com.");		
		}
		if(empty($subject)){
			$this->m->addMessage("email-form", "error", "You must include a subject.");
		}
		if(empty($message)){
			$this->m->addMessage("email-form", "error", "You must include a message.");
		}
		if($this->m->countMessages() > 0){
			//Stop
			return FALSE;
		}else{
			//Continue
			$save = mysql_query("/*query left empty on purpose (not my problem) */") or die(mysql_error());
			
			if($save){
				$headers = 'FROM: '.$from."\r\n".
						   'Reply-To: support@domain.com'."\r\n".
						   'X-Mailer: PHP/'.phpversion();
				$send = mail($to, $subject, $message, $headers);
				if($send){
					$this->m->addMessage("email-form", "success", "Your message has been sent.");
					return TRUE;
				}else{
					$this->m->addMessage("email-form", "error", "Your message could not be sent.");
					return FALSE;
				}
			}else{
				$this->m->addMessage("email-form", "error", "Your message could not be sent.");
				return FALSE;
			}
			
		}

The all famous classic mail bug. Try the following:

function sendVerificationEmail($email, $code){
		$to = $email;
        $subject = "Please activate your account at ".SITE_NAME;
        $from = "registration@domain.com";
        
        $headers = "From: $from\n".
						   "Reply-To: support@domain.com\n".
						   "X-Mailer: PHP/".phpversion();
				
       
        $message = "Welcome to domain.com\n" .
            "We see that you recently opened an account with us.\n" .
            "Before you can start using our services you need to activate your account.\n" .
            "Follow the link below to activate your account.\n" . 
			SITE_URL."user/activate/?e=" . $to . "&c=" . $code . "&action=activate\n\n" .
            "_______________________\n\n" . "This is an automated response from ". SITE_NAME .
            "\n\n" . "Please do not respond to this email.";

        if(mail($to, $subject, $message, $headers)){ //bug fix
        	return true;
        }else{
        	return false;
        }
	}

If that doesn't work then in addition to that you might need to change the mail() inputs.

Miraculously, i seem to have fixed the bug myself...of of a couple of speculations. I ran a few tests, first i sent an email normaly with an email that does not exist, and it sent with the host@host299.hostmonster.com.

but then i actually created the email that i used before, but didnt exist. so i ran the function with the same exact vars/emails n all and it sent exactly how it was i have been trying to get it to send.

I also tried this test with the same procedures and it worked the same ways.

so my conclusion is, that the mail function pings my server to see if the "from" email actually exists. and if it exists, then it will use the inputed email. and if the email does not exist, the mail function will use the hosts defualt gateway.

thanks for your response!

i hope i helped somone else out along the way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.