treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] PHP Email Problems...

  • OK, so...I am currently working on an email form for a client who wants to use the following encryption to encrypt emails sent from his site ( please don't ask me why, I haven't the slightest idea why lol)...


    <?php
    function encode($thetext)
    {
    $iv = "51901410686694700275125677623053";
    $key = "super secret encryption key";
    $text = $thetext;
    $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
    $padding = $block - (strlen($text) % $block);
    $text .= str_repeat(chr($padding), $padding);
    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv);
    $encodedMsg = base64_encode($crypttext);
    return ($encodedMsg) . "\n<br/>";
    }
    ?>

    My Problem is, I cannot figure out how to get the encode() function to parse the posted data and properly display in the email sent from the server...Here is my email script as is stripped as much as possible


    <?php
    $recipient = "email@email.com";
    $subject = "Super Secret Encrypted Message";
    $name = encode($_REQUEST['client-name']);
    $contactPref = encode($_REQUEST['contact-preference']);
    $email = encode($_REQUEST['email']);
    $phone = encode($_REQUEST['phone']);
    $state = encode($_REQUEST['state']);
    $county = encode($_REQUEST['county']);
    $primary = encode($_REQUEST['primary-care']);
    $clinic = encode($_REQUEST['clinic-name']);
    $docCity = encode($_REQUEST['physicians-city']);
    $inquiry = encode($_REQUEST['questions-comments']);

    $emailBody .= "Name: " . $name;
    $emailBody .= "Contact Preference: " . $contactPref;
    $emailBody .= "Email: " . $email;
    $emailBody .= "Phone: " . $phone;
    $emailBody .= "State: " . $state;
    $emailBody .= "County: " . $county;
    $emailBody .= "Primary Care: " . $primary;
    $emailBody .= "Clinic Name: " . $clinic;
    $emailBody .= "Physician's City: " . $docCity;
    $emailBody .= "Questions/Comments: " . $inquiry;

    mail($recipient, $subject, $emailBody, "From: $email");

    ?>

    And Of course, that doesn't work...It shoots me a 500 error :(

    If anyone has any suggestions i would more than appreciate it!

    Thanks guys...The solution is simple and on the tip of my tongue but i just can't get it out.

    p.s. I removed all validation and comments to make it really really minimal...
  • I think this
    $email = encode($_REQUEST['email']);
    might be causing problems for this
    mail($recipient, $subject, $emailBody, "From: $email");
  • Funny you say that, because I already thought that would be an issue and passed $_REQUEST['email'] through the email validation function like this...
    if ( isValidEmail($_REQUEST['email']) )

    But I coompletely overlooked the actual mail() function itself...

    I will give that a go and see what happens...Thanks a lot for noticing that!
  • Nevermind, figured out the issue, did a phpinfo() on the server...turns out mcrypt is not installed...i was told it was...guess i should have double checked anyhow.
  • ha good old phpinfo :D