Link to home
Start Free TrialLog in
Avatar of prashanth ag
prashanth ag

asked on

Invalid Address in PHPMailer

Hi,

I want to send an email with PHP page itself it was working fine before  after i add extra textbox in that form  user needs to add mentor E-mail id
but it shows error
"Invalid address "
"Notice: Undefined variable: mentor_email1 in"

require '../PHPMailer/class.phpmailer.php';

 if (!isset($_POST['mentoremail'])) 
	 {
	 
	$mentor_email1 ="";
	$mentor_email1= $_POST['mentoremail'];
	}

$mail->addAddress($mentor_email1);
  if(!$mail->send()) {
        echo '<div class="alert alert-danger">Email error:bla bla n.</div>';
    }

<div class="control-group">
			  <label class="control-label" for="descinput">Mentor Email ID(subordinate)</label>
			  <div class="controls">

			
			 <input type="text"  name="mentoremail" size="30"    >
			  
			  
			  </div>
			</div>

<div class="controls">
                     <button id="submit" class="btn btn-primary" type="submit" name="submit" value="Login">Apply</button>
               </div>

Open in new window

SOLUTION
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kimputer
Kimputer

Actually, this will fail if previous page is correctly set up:

$mail->addAddress($mentor_email1);

That's because $mentor_email1 is never assigned anything if the value $_POST['mentoremail] IS SET!
For now, the quickest way is to change
 if (!isset($_POST['mentoremail']))
to
 if (isset($_POST['mentoremail']))
Avatar of prashanth ag

ASKER

Hi,

I changed as you mentioned  but it shows same error
Notice: Undefined variable: mentor_email in and
Invalid address:
How to post data to the same page ?
example
$mentor_email1= $_POST['mentoremail'];

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
can you post the complete code?
@Squinky

I made changes as you mentioned but it shows

Fatal error: Call to a member function addAddress() on a non-object in
Notice: Undefined variable: mail in
As I said - it looks like you've left out all your other code - you're missing a `$mail = new PHPMailer;`.
thanks Squinky and Loganathan Natarajan