Send PDF link in email based on radio button selection

You should use the same name attribute for your 2 radio inputs. So let’s say that name is language. If language is set, you have 2 options represented by value, either English or Chinese.

In the code you posted, that is mainly your problem. You set your $radio variable to be $_POST['language1'] but $_POST['language1'] will ALWAYS be English because the Chinese value is set by $_POST['language2']

in your form markup, change your radio input name values

<div class="overflow-hidden">
  <form class="text-center" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

    <div class="col-md-6">
      <p class="tns">First Name *:</p>
      <input type="text" name="clname" placeholder="First Name" required />
    </div>
    <div class="col-md-6">
      <p class="tns">Last Name *:</p>
      <input type="text" name="clsurname" placeholder="Last Name" required />
      <input type="radio" name="language" value="English">English 
      <input type="radio" name="language" value="Chinese">Chinese
    </div>

    <hr>

    <div class="overflow-hidden">
      <div class="col-sm-6 col-sm-offset-3">
        <input type="submit" name="submit" value="submit" />
      </div>
    </div>
  </form>
</div>

In your PHP:

  • Change references of language1 to language
  • Use ternary operator to set $fileatt. If $radio is English output English url to file. Output Chinese url otherwise.

.

if(isset($_POST['submit']) && isset($_POST['language'])){

  $radio       = $_POST['language'];
  $fileatt="English" == $radio ? "http://example.com/english.pdf" : "http://example.com/chinese.pdf" ;
  $fileatttype = "application/pdf";


  $headers="From:" . $_POST['clname'] . ' <'. $_POST['clemail'] .'>' . "\r\n";
  $mail = get_option('admin_email');
  $subject = "Testing";


  $message="Name: " . $_POST['clname'] . ' ' . $_POST['clsurname'] .'\n\n
  Email:'.$_POST['clemail'].'\n\n Radiovalue:' . $radio . '\n'. $fileatt;

  wp_mail($mail,$subject,$message,$headers);
  $emailsent= true;
}